Using Android Studio

Using Android Studio is a convenient way to add Flutter to native projects.

In the native category, open File > New > New Module… Menu, select Create Flutter Module.

The Android Studio plugin automatically configures Android projects to add dependencies to the Flutter Module.

Manual integration

You can do it without Android Studio, but manual integration can pass

Create a Flutter Module

flutter create -t module --org com.example my_flutter
Copy the code

2. Java 8 configuration

Flutter’s Android engine needs to use Java 8 features. When associating a Flutter Module with a main Android project, make sure that the main project build.gradle has the following configuration

android { //... CompileOptions {sourceCompatibility 1.8 targetCompatibility 1.8}}Copy the code

Add Flutter Module dependencies

Add the Flutter Module to the main project and set the Flutter Module to settings.gradle as follows:

include ':app'                                    // assumed existing content
setBinding(new Binding([gradle: this]))                           
evaluate(new File(                                                   
  settingsDir.parentFile,                                           
  'my_flutter/.android/include_flutter.groovy'   
))  
Copy the code

Note the file location. The Settings above should ensure that the Flutter Module is in the same level of directory as the native project

Add dependencies in APP settings.gradle

dependencies {
  implementation project(':flutter')
}
Copy the code