Add Flutter Module to Android App

tanya anand
3 min readApr 26, 2022

Welcome to a very very unexplored world…

I will try to explain what are the ways, we can add flutter to Android App.

There are mainly two ways to add a flutter module to an android App.

  1. Add the flutter module as a sibling of the host App.
  2. Integrate the flutter module as an AAR to host App.

Let's learn how to create a flutter module and host app first.

Creating Android Host App

  1. Start Android Studio on your system and click on Start a new Android Studio project.

2. Choose Empty Activity and click on Next.

3. Enter all required details and click finish.

Make sure you are keeping host App in a separate folder, this will help us later 😊

users/flutter-integration/hostApp

Now, we are all set for the Android host App.

Creating Flutter module

The Flutter module should be added as a sibling to the native Android app. Assuming we have an android project at users/flutter-integration/hostApp, where hostApp is the name of your Android project folder.

Now, we have to create the Flutter module in users/flutter-integration folder.

  1. Open the terminal and Navigate to users/flutter-integration.
  2. Type below commands

Now, your flutter module will be generated.

And new folder structure will be

flutter-integration -> hostApp + my_flutter

Wooooh………..👌🏾

Method 1

Depend on the module’s source code: This enables a one-step build for both your Android project and Flutter project. This is convenient when working on both parts simultaneously, It also helps a lot in debugging flutter code, hot reload, and hot restart.

but the team must install the Flutter SDK to build the host app.

Follow these steps to add Flutter to the native Android app:

  1. Add below to your host app settings.gradle

Assuming my_flutter is a sibling to hostApp.

2. Introduce an implementation dependency on the Flutter module from your app. Add below to your Build.gradle(app)

3. Then sync the Gradle by clicking on Sync Now button. This will add some additional code and files to the host app for making it flutter-dependent.

All Set… We are ready to fly🧚🏼.

Method 2

This method packages our Flutter library as a generic local Maven repository composed of AARs and POMs artifacts. This allows our team to build the host app without installing the Flutter SDK if you already have AARs. we can then distribute the artifacts from a local or remote repository.

Follow these steps to add Flutter to the native Android app:

  1. open the Flutter module at users/flutter-integration/my_flutter, and then run:

2. Follow the instructions shown in the terminal.

edit app/build.gradle in your host app so that it includes the local repository and the dependency:

All set !!!

--

--