Flutter mixed development-Android

Why Flutter ?

 
older_crossed_platform.png

Flutter framework and application

Framework and Source Code

Overall framework
 
flutter_struct_base.jpg
Source Code
 
flutter_struct_function.png

So from the above analysis, we can see that in order to achieve no difference in Flutter's platform, Google has mainly done adaptation work in the PlatForm Integration and Dart: UI part.

APK (Android application) structure

We uncompressed a release of the mixed development APK package to explore what changes have occurred in the package after adding Flutter and what the corresponding effects of these changes are.

 
flutter._apk_change_graffle.png

The change point can be clearly seen from the mark in the picture above

  • Change 1

    Not marked in the figure, but I believe most developers should be able to guess that the code of PlatForm Integration (FutterActivity, FlutterApplication, FlutterView etc.) is entered in dex

  • Change 2

    The 4 files under assets, all of which are arm instructions

    • isolate_snapshot_data/isolate_snapshot_instr

      AOT compilation corresponding to our Flutter code, used to create a new isolate

    • vm_snapshot_data/vm_snapshot_instr

      Used to initialize Dart VM, provide services such as runTime, gc, etc.

    Because this part of the content is compiled and generated by gen_snapshot and stored in the App data directory, so

    Provides the possibility for future dynamic updates.

  • Change 3

    The ICU Dart Language package provides language-related data information.

  • Change 4

Flutter Engine Code layer

Flutter mixed mode

I believe that for most applications, the cost of rebuilding an app from scratch is quite high, so hybrid development has become their first choice to try Flutter.

Idle fish mode

Dual Branch coexistence (Flutter mode && Standalone mode)

Standalone mode: pure Native development or platform packaging mode

Flutter mode: The development of flutter related functions, library generation, compilation and debugging are all processes defined by Flutter.

  • advantage

In Standalone mode, pure Native developers and packaging platforms are unaware of Flutter. In this case, the Flutter related code can be considered as a regular third-party library file.

  • Preparation

    Clarify the dependency on Flutter in Standalone mode and extract them into an aar library.

  • Development steps

    1. Develop flutter related functions in Flutter mode.
    2. Package the code into an aar library and upload it to the repository for version control.
    3. Switch the branch to Standalone mode, and modify the version numbers of related dependent packages.

    Of course, this method will encounter many other problems in the actual development process, such as writing aar library scripts under complex processes, such as code synchronization in two modes.

Google mode

How loud is the development of the hybrid mode with Flutter, Google has created a Wiki specifically for this problem and has updated 42 versions for 4 months.

Create Flutter Module mode
1.1.1 Switch flutter branch

If used directly

$ cd some/path/
$ flutter create -t module my_flutter

  

There will be an error that the command module cannot be identified. Find the reason and find that our default clone branch is the beta version of flutter and does not support the module command, so first need

flutter channel
flutter channel master
flutter upgrade

  

Switch the branch to master and perform the upgrade operation.

1.1.2 Create a Flutter module template
flutter create -t module flutter_module

  

At this time, you will see a new flutter_module added to the project, which contains .android, .ios and the key include_flutter.groovy files

1.1.3 Add Flutter to an existing project
  • Add in settings.gradle in the root directory of the android project

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

      

  • Add dependencies in the app's build.gradle

  • dependencies {
      implementation project(':flutter')
    

     

1.1.4 In summary

Simply put, Google has established a logical dependency chain for the Insert flutter module under the premise of maintaining maintenance costs and development costs.

flutter_module/.android/include_flutter.groovy ->
flutter_module/.android/Flutter/build.gradle ->
$flutterRoot/packages/flutter_tools/gradle/flutter.gradle 

  

Use flutter command && in $ flutterRoot / packages / flutter_tools / lib /

$AndroidRoot/build-tools/buildToolsVersion/中的android command

Complete the packaging operation in the mixed development mode.



Author: Flutter Programming Guide
link: https: //www.jianshu.com/p/48daeb72c44c

Guess you like

Origin www.cnblogs.com/wjw334/p/12693178.html