Modular engineering design of the whole Flutter
- Fluttercore-flutter module engineering
- FluttercoreWrapper – Wrapper works for aar/framework that is packaged with flutter
- Flutterbussiness – Plugin/Packages for FLUTTER, abstraction of some common modules on the DART side
I. New Flutter module project
flutter create -t module --org com.huya.hive fluttercore
Copy the code
The engineering structure is shown in the figure:
It contains an.Android project and an.ios project, both of which can be opened by right-clicking on Fluttercore and used to debug dart code
2. Build aar business module package
The package built here does not contain the code for the Flutter Framework and the Flutter Engine.
Flutter build aar --no-debug --no-profile --no-pub --target-platform Android-arm, Android-arm64 --build-number 1.0.1 flutter build ios-framework --no-debug --no-profile --no-pubCopy the code
The aar structure constructed is shown as follows:
Dart code is included in libapp.so included in the build result
Create android common project fluttercoreWrapper
Create a new module fluttercore in the project
Add a fat-AAR dependency to project-level build.gradle
The classpath 'com. Making. Kezong: fat - the aar: 1.3.6'Copy the code
The reason for adding fat-AAR is that the AAR built in the previous step only contains dar code and does not contain the dependent libraries, libFlutter. So (which contains different eabi) and flutter_embedding_relex.jar, so this step includes both libraries.
Note that both files were downloaded from a remote server. I have been stuck here for a long time thinking that they were generated by a local build, but they are not
maven {
url "https://storage.googleapis.com/download.flutter.io"
}
Copy the code
The complete project-level build.gradle looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { maven { url "http://nexus.huya.com:8081/repository/maven-public" allowInsecureProtocol = true } google() MavenCentral dependencies ()} {the classpath 'com. Android. View the build: gradle: 4.1.2' classpath 'com.github. Kezong :fat-aar:1.3.6'}} Task Clean (type: Delete) { delete rootProject.buildDir } allprojects { repositories { maven { url "http://nexus.huya.com:8081/repository/maven-public" allowInsecureProtocol = true } maven { url "https://storage.googleapis.com/download.flutter.io" } google() mavenCentral() } }Copy the code
The build.gradle module of Fluttercore deals mainly with aar merging
plugins { id 'com.android.library' } apply plugin: 'com.kezong.fat-aar' def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } android { compileSdkVersion 31 defaultConfig { minSdkVersion 22 targetSdkVersion 31 versionCode 1 versionName "1.0" consumerProguardFiles "consumer-rules.pro"} buildTypes {release {minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility Javon_1_8} Repositories {flatDir {dirs 'libs'}} ndkVersion '21.0.6113669'} def engineVersion = file("${flutterRoot}/bin/internal/engine.version").text.trim() println "----->flutter enginversion = ${engineVersion}" Dependencies {embed (name:"flutter_release-1.0.1", Ext: "aar)" embed "IO flutter: flutter_embedding_release: 1.0.0 - ${engineVersion}" embed "IO. Flutter: armeabi_v7a_release: 1.0.0 - ${engineVersion}" embed "IO. Flutter: arm64_v8a_release: 1.0.0 - ${engineVersion}"} apply from : ".. /publish.gradle"Copy the code
4. Build aggregate AAR
Execute in the fluttercoreWraaper root directory
./gradlew :fluttercore:assembleRelease
Copy the code
The obtained polymeric AAR can be directly relied on by other native projects, and its catalog results are as follows:
Five. Problem record
- So, flutter_embedding_xxx.jar Where is the local path?
These files are added via dependencies and are themselves downloaded from the remote Maven repository. The following version number is the engineversion of the local Flutter. Its location in fluttersdk directory ${flutterRoot} / bin/internal/engine version file.
- 2. How to modify the DART code after dependency?
Dart code will be included in the module project of Flutter by default, packaged as libapp.so
- 3. Why doesn’t the aar contain libflutter. So, flutter_embedding_xxx.jar?
These two files (actually multiple, depending on the type of eABI) do not enter an AAR during a flutter build aar by default and need to be packaged via a FAT AAR
Vi. Analysis of flutter construction process
After the repair.