Introduction to the
The update speed of Flutter is still very fast. In order to avoid unnecessary problems, this article is based on the version of Flutter
Idle fish Technology Group
Flutter source code integration
Add Flutter to Existing apps
This is the first way I tried to access the native Flutter layer after completing the development of Flutter layer. After all, the official is always the first choice. The official Add-to-app can see their progress in this aspect. Moreover, this method is more convenient for debugging with flutter Attach
Aar product integration
The Flutter project is a module project generated by the Flutter create -t module my_flutter. This project can generate an ARR file for us to avoid the unnecessary hole created by manually creating the Module project (if you want, you can also create the module project). Just pack the source code and plugins with reference to flutter. Gradle, that’s what we did with this article.)
./gradlew assembleRelease
aar
release
Flutter model
For Flutter, it supports the usual debug, Release,profile and other modes, but it is different. Debug mode: Indicates the Dart JIT mode, also called check mode or slow mode. Supports devices, emulators (iOS/Android), assertions are enabled in this mode, including all debugging information, service extensions, and debugging AIDS such as the Observatory. This pattern is optimized for rapid development and operation, but not for execution speed, package size, and deployment. In Debug mode, compilation uses JIT technology and supports the popular sub-second stateful Hot Reload. Release mode: Corresponds to Dart’s AOT mode, which is deployed to end users. Only real machines are supported, not emulators. Turn off all assertions, remove as much debugging information as possible, and turn off all debugging tools. Package sizes are optimized for fast startup and execution. Disabled all debugging AIDS, service extensions. Profile mode: Similar to Release mode, but with additional support for profile-mode service extensions, tracing support, and minimization of dependencies needed to use trace information, for example, observatory can be connected to processes. The reason the Profile does not support emulators is that diagnostics on emulators do not represent true performance.
Reference the AAR package in Android
//app:build.gradle
//name: same as our AAR file name
// ext: This file format
dependencies {
...
implementation(name: 'flutter-release', ext: 'aar')... }Copy the code
Aar packages are placed in the LIBS folder
Sync Project with Gadle Files
Aar remote dependency
Here I put the library on Github to provide native development remote dependencies. The benefit is that Android developers can focus on their own business development, and updates related to the Flutter layer will not change to them.
- In flutter project open the android/flutter/build gradle
dependencies {
testImplementation 'junit: junit: 4.12'
implementation 'com. Android. Support: support - v13:27.1.1'
implementation 'com. Android. Support: support - annotations: 27.1.1'
}
// Add the following code
apply plugin: 'maven'
ext {
// Clone the local address of the project from Github
GITHUB_REPO_PATH = "D:\\f\\github\\test"
PUBLISH_GROUP_ID = 'com.test'
PUBLISH_ARTIFACT_ID = 'flutter_library'
PUBLISH_VERSION = '1.0.0 - the SNAPSHOT'//SNAPSHOT does not care about the specific version for native development
}
uploadArchives {
repositories {
mavenDeployer {
// Local Maven repository address, or remote Maven repository
def deployPath = file(project.GITHUB_REPO_PATH)
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId project.PUBLISH_GROUP_ID
artifactId project.PUBLISH_ARTIFACT_ID
version project.PUBLISH_VERSION
}
}
}
}
Copy the code
- . Android /
./gradlew uploadArchives
Copy the code
- submit
"D:\\f\\github\\test"
The contents of this directory are uploaded to Github - The Android project project: build. Gradle
allprojects{
repositories {
...
maven{ url 'own making https://raw.githubusercontent.com/ username/library/master'}... }}Copy the code
- Android app project: build. Gradle
dependencies {
...
implementation 'com. Test: flutter_library: 1.0.0 - the SNAPSHOT'. }Copy the code
Sync Project with Gadle Files
After the synchronization is complete, you should be able to see the corresponding package in the External Libraries
comb
- Gradle is cached for 24 hours by default. If you want to check the build before each build, add it to build.gradle
configurations.all {
...
resolutionStrategy.cacheChangingModulesFor 0.'seconds'. }Copy the code
- Because I am not very familiar with native and Gradle, I may not do integration in the right way
- There are also downsides to changing build.gradle in the Flutter project when you rely on aar packages remotely
We were specifically told not to modify this file…
This file will be officially reset at least every time Flutter is updated
so… If there is a better way, please let me know…
reference
- In-depth understanding of Flutter compilation and optimization
- Best practices for continuous integration of the Idle Fish Flutter hybrid Engineering