How to create Flutter container and applet based on Android
By modifying the Flutter SDK, building an Android-based Flutter container and applet creation method solves the problem that users need to use multiple APPs at the same time, implementing low-cost migration and aggregation of multiple applets, improving user experience, and providing flexible development and configuration options.
Patent Information
- Application Number
- CN202210974522.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-15
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-08-15
AI Technical Summary
In the prior art, users need to use multiple APPs at the same time, resulting in switching between APPs increasing the user's usage cost and unfriendly experience.
By modifying the Flutter SDK, build an Android-based Flutter container and applet creation method, support multiple applets to run simultaneously, and provide a container resident mechanism to achieve rapid startup.
It realizes low-cost migration and aggregation of multiple mini programs, issues business programs according to user needs, supports multi-process operating environment, improves user experience, and provides flexible development and configuration options.
Smart Images

Figure CN115437762B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of mobile application technology, and in particular to a method for creating a Flutter container and a mini-program based on Android. Background Art
[0002] With the rapid development of mobile business, a manufacturer can develop more than dozens of mobile apps. In the existing technology, the business or target population is finely divided, and a multi-APP vertical coverage strategy is planned. Different roles (jobs) use different apps, which not only makes the business more focused, but also allows for rapid iteration of apps. However, as the business boundaries extend, the same user may have multiple roles or need to participate in multiple businesses at the same time. When working, the user will need to use multiple apps of a manufacturer at the same time. Switching between multiple apps will greatly increase the user's usage cost and the experience is very unfriendly.
[0003] To solve the above problems, the general approach in this field is to create a super APP and then aggregate different business programs in the form of "mini programs", such as WeChat mini programs, Alipay mini programs, etc. Most of the industry is hybrid development based on native, but the main business APPs of some manufacturers are developed based on the cross-platform framework Flutter. In addition, there is currently no mini program solution based on Flutter on the Android platform in the industry.
[0004] For other mini-program solutions in the industry, such as WeChat and Alipay mini-programs, they are basically rendered through WebView, but the rendering effect and experience of WebView are still far behind the native implementation. On the contrary, Flutter's self-drawing engine can achieve a close to native experience, which is more efficient than WebView. Summary of the invention
[0005] Based on the Flutter version of the mini-program framework, in order to support the use of various businesses of manufacturers in the form of mini-programs, it can not only migrate and aggregate the current business modules at low cost, but also issue corresponding business programs according to the actual needs of users. In view of this, the present invention proposes a method for creating a Flutter container and a mini-program based on Android, including the following steps:
[0006] Modify the Flutter SDK or customize the Flutter SDK to generate the mini-program installation files corresponding to each project and the main program installation files that support the running of the mini-programs;
[0007] During runtime, the corresponding mini-program installation file is downloaded according to the user's operation, and then installed and run;
[0008] Building a Flutter container includes: using Activity as a single Flutter container, pre-registering multiple Activities in the AndroidManifest manifest file in the main project, and specifying different processes; maintaining the relationship between the currently running mini-program and the container in the main project: when the main project receives an instruction to start a mini-program, first determine whether the mini-program is already in the running container. If so, directly start the corresponding container. If not, select one from the unstarted containers to start. After the new container is started, send a broadcast to the main program, and the main program updates the relationship between the currently running mini-program and the container; after miniAppActivity is started, create FlutterEngine, and start the mini-program name as needed, pass the corresponding libapp.so path to FlutterEngine in the form of FlutterShellArgs, so as to execute Flutter to load the corresponding mini-program code execution; Flutter container execution cache strategy: under normal circumstances, when the mini-program exits, the current process will be automatically killed when the Activity finishes to release resources. If it is set as a resident mini-program, the container will be kept in the background, and the container will be re-started at the next startup to achieve fast startup;
[0009] Build a multi-process operating environment, use DartEntryPoint and window.defaultRouteName to determine the running mode of the mini program or APP, and schedule it.
[0010] Furthermore, the modification of the Flutter SDK includes adding a new mini-program compilation instruction flutter buildminiApp. The compilation process of the mini-program compilation instruction is as follows:
[0011] Compile and generate installation files that support the main program APK and mini-programs;
[0012] Modify the APK resource compilation process and remove the "package" path for mini-program resources;
[0013] Modify the APK resource compilation process to support automatic decompression and repackaging of APK when compiling mini-program installation files.
[0014] Furthermore, the generation of the mini-program installation files corresponding to each project and the main program installation files supporting the mini-program operation includes:
[0015] According to the configuration of the mini-program platform, pull the Flutter project code that needs to be packaged into a mini-program from the code repository and place it in the specified directory of the main project;
[0016] Run the Flutter SDK customized command compilation in the root directory of the main project. This command will add each project in the mini-program directory to the pubsepc.yaml dependency of the main project in the form of package, and then execute the main program Flutterapk building process. After the building is completed, the main program installation package is generated;
[0017] After the main program is built, it will enter the project directory of each mini program in turn to first build the apk file of the mini program, and then decompress and extract the resource directory and libapp.so file to package them into the mini program installation package.
[0018] Furthermore, the corresponding mini-program installation file is downloaded according to the user's operation, installed and run, and the specific running process is as follows:
[0019] The user selects the mini program they want to use in the mini program store. After clicking, the corresponding mini program installation file will be automatically downloaded from the background and the installation file will be verified;
[0020] Start a new process and container, and specify the corresponding installation file to execute when FlutterEngine starts;
[0021] Switch to the new interface, and wait for the mini program interface to render successfully before the user can operate.
[0022] Furthermore, the customized Flutter SDK includes automatically building the applet main project and container and automatically building the applet installation file:
[0023] Automatically build the mini-program main project and container: When the build starts, the mini-program Flutter project in the specified directory will be automatically scanned, and package dependencies will be automatically added to the main project pubspec.yaml. Then all package dependencies of the main project will be analyzed, and possible version conflicts after merging multiple projects will be automatically handled. Android plug-in dependencies will be added to the main project, and resource files of each mini-program project will be copied to the main project. Switch to the root directory of the main project, start building the main project, and generate the main project apk file.
[0024] Automatically build the mini-program installation file: Switch to the mini-program project directory, start building the mini-program project, and after generating the apk file, unpack it to obtain the aot file libapp.so and resource files, and re-sign and package them to generate the miniapp mini-program installation file.
[0025] Furthermore, the DartEntryPoint determination method specifically includes:
[0026] If running as a mini program, specify DartEntryPoint as a specific entry function when the container starts to create FlutterEngine. Based on the different entry functions, it can be determined whether the current operation is an app or a mini program.
[0027] Furthermore, the window.defaultRouteName judgment method specifically includes: if running as a mini program, when the container starts to create FlutterEngine, the specified parameters are set by setInitialRoute. After startup, whether window.defaultRouteName is "miniApp" in the Dart code is used to determine whether it is running in the mini program. If yes, it runs in the mini program.
[0028] The beneficial effects of the present invention are as follows:
[0029] By modifying the Flutter SDK, the present invention can automatically build a Flutter container and a mini-program running package according to multiple Flutter projects. Developers can still develop applications with the Flutter APP project structure, and can flexibly configure them to run in the form of an independent APP or a mini-program.
[0030] For the scenario where multiple mini-programs are running at the same time, the present invention provides a multi-process + Flutter container solution, which can support the simultaneous running of multiple mini-program applications. For the scenario where a certain mini-program is used frequently, an optional container resident mechanism is provided, that is, the mini-program still retains the previous running status after exiting, and can be quickly started the next time, greatly improving the user experience.
[0031] In view of the possible differences in requirements between mini-programs and independent apps, the present invention provides multiple ways for developers to determine whether the current operating environment is running as a mini-program or an independent app.
[0032] In response to the demands of different users to use different mini-programs, the present invention provides a mini-program application store solution, where users can search, download, install, uninstall, and upgrade the mini-program applications they need to use within the main program. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 The applet compilation flow chart of the present invention;
[0034] Figure 2 The mini-program application store interface diagram of the present invention;
[0035] Figure 3 The applet and container correspondence diagram of the present invention;
[0036] Figure 4The applet startup flow chart of the present invention. DETAILED DESCRIPTION
[0037] The present invention is further described below in conjunction with the accompanying drawings, but the present invention is not limited in any way. Any changes or substitutions made based on the teachings of the present invention belong to the protection scope of the present invention.
[0038] The creation method of the present invention is divided into two parts: compile time and run time. The specific process of the compile time is as follows:
[0039] The compilation phase mainly involves modifying the Flutter SDK to build the mini-program installation files corresponding to each project from multiple Flutter repositories, as well as the main program installation files that support the running of the mini-programs. Figure 1 As shown, the specific compilation process is as follows:
[0040] 1. According to the configuration of the mini-program platform, pull the Flutter project code that needs to be packaged into a mini-program from the code repository and place it in the specified directory of the main project.
[0041] 2. Run the Flutter SDK customized command compilation in the root directory of the main project. This command will add each project in the mini-program directory to the pubsepc.yaml dependency of the main project in the form of a package, and then execute the main program Flutter apk building process. After the building is completed, the main program installation package is generated.
[0042] 3. After the main program is built, enter the project directory of each mini program in turn to first build the apk file of the mini program, then decompress and extract the resource directory and libapp.so file to package them into the mini program installation package.
[0043] Among them, the modification of Flutter SDK is mainly to add the mini program compilation instruction flutter build miniApp. The general compilation process
[0044] Among them, the modification of Flutter SDK is mainly to add the mini program compilation instruction flutter build miniApp. The general compilation process is shown in the attached Figure 1 The applet compilation flow chart mainly includes:
[0045] 1) Support the compilation and generation of main program APK and mini program installation files.
[0046] 2) Modify the APK resource compilation process and remove the "package" path for mini-program resources.
[0047] 3) Modify the APK resource compilation process to support automatic decompression and repackaging of APK when compiling mini-program installation files.
[0048] The runtime includes:
[0049] The runtime stage mainly downloads the corresponding mini program installation file according to the user's operation, installs and runs it. The mini program store interface is attached. Figure 2 Summary of the Mini Program App Store interface. The specific operation process is as follows:
[0050] 1. The user selects the mini program he wants to use in the mini program store. After clicking, the corresponding mini program installation file will be automatically downloaded from the background and the installation file will be verified.
[0051] 2. Start a new process and container, and specify the corresponding installation file to execute when FlutterEngine starts.
[0052] 3. Switch to the new interface, and wait for the mini program interface to render successfully before the user can operate.
[0053] Flutter SDK customization main technical solutions:
[0054] 1. Automatically build the mini-program main project and container: When the build starts, the mini-program Flutter project in the specified directory will be automatically scanned, and the package dependency will be automatically added to the main project pubspec.yaml. Then all package dependencies of the main project will be analyzed, and possible version conflicts after merging multiple projects will be automatically handled. The Android plug-in dependency will be added to the main project, and the resource files of each mini-program project will be copied to the main project. Switch to the root directory of the main project, start building the main project, and generate the main project apk file.
[0055] 2. Automatically build the mini-program installation file: Switch to the mini-program project directory, start building the mini-program project, and after generating the apk file, unpack it to obtain the aot file libapp.so and resource files, and re-sign and package them to generate the miniapp mini-program installation file.
[0056] The main technical solutions of Flutter container + multi-process are as follows:
[0057] 1) Implementation of Flutter multi-container operating environment
[0058] a. Implementation of Flutter container: Use Activity as a single Flutter container, pre-register multiple Activities in the AndroidManifest manifest file in the main project, and specify different processes, that is, different Activity containers run in different processes.
[0059] b. Flutter container and mini-program management solution: Maintain the relationship between the currently running mini-program and the container in the main project. Figure 3 The correspondence diagram between mini-programs and containers. When the main project receives an instruction to start a mini-program, it first determines whether the mini-program is already in the running container. If so, it directly starts the corresponding container. If not, it selects one from the unstarted containers to start. After the new container is started, it sends a broadcast to the main program, and the main program updates the relationship between the currently running mini-program and the container.
[0060] c. Flutter container creation method: After miniAppActivity is started, create FlutterEngine and start the mini program name as needed. Pass the corresponding libapp.so path to FlutterEngine in the form of FlutterShellArgs to execute Flutter to load the corresponding mini program code. Refer to the attached Figure 4 The applet startup flowchart.
[0061] d. Flutter container cache strategy: Under normal circumstances, when the applet exits, the current process will be automatically killed when the Activity finishes to release resources. If it is set as a resident applet, the container will be kept in the background, and the container will be re-started the next time it is started to achieve fast startup. The present invention provides a multi-process + Flutter container solution that can support the simultaneous running of multiple applet applications, and for scenarios where a certain applet is used frequently, an optional container resident mechanism is provided, that is, the applet still retains the previous running state after exiting, and can achieve fast startup the next time it is started, greatly improving the user experience.
[0062] 2) How to determine the operation mode of the mini program or APP
[0063] a.DartEntryPoint judgment method: If running as a mini program, when the container starts to create FlutterEngine, specify DartEntryPoint as a specific entry function, such as miniAppMain(). By different entry functions, you can determine whether it is currently running as an APP or a mini program.
[0064] b.Window.defaultRouteName judgment method: If running as a mini program, when the container starts to create FlutterEngine, set the specified parameters through setInitialRoute, such as setting it to "miniApp". After startup, you can wait in the Dart code to determine whether window.defaultRouteName is "miniApp" to determine whether it is running in the mini program.
[0065] The present invention is applicable to a system developed based on the Flutter framework and implementing a mini-program using the Flutter framework.
[0066] The beneficial effects of the present invention are as follows:
[0067] By modifying the Flutter SDK, the present invention can automatically build a Flutter container and a mini-program running package according to multiple Flutter projects. Developers can still develop applications with the Flutter APP project structure, and can flexibly configure them to run in the form of an independent APP or a mini-program.
[0068] For the scenario where multiple mini-programs are running at the same time, the present invention provides a multi-process + Flutter container solution, which can support the simultaneous running of multiple mini-program applications. For the scenario where a certain mini-program is used frequently, an optional container resident mechanism is provided, that is, the mini-program still retains the previous running status after exiting, and can be quickly started the next time, greatly improving the user experience.
[0069] In view of the possible differences in requirements between mini-programs and independent apps, the present invention provides multiple ways for developers to determine whether the current operating environment is running as a mini-program or an independent app.
[0070] In response to the demands of different users to use different mini-programs, the present invention provides a mini-program application store solution, where users can search, download, install, uninstall, and upgrade the mini-program applications they need to use within the main program.
[0071] As used herein, the word "preferred" is intended to be used as an example, instance, or illustration. Any aspect or design described herein as "preferred" is not necessarily to be construed as being more advantageous than other aspects or designs. On the contrary, the use of the word "preferred" is intended to present concepts in a specific way. The term "or" as used in this application is intended to mean an inclusive "or" rather than an exclusive "or". That is, unless otherwise specified or clear from the context, "X uses A or B" means any one of the naturally included permutations. That is, if X uses A; X uses B; or X uses both A and B, then "X uses A or B" is satisfied in any of the foregoing examples.
[0072] Moreover, although the present disclosure has been shown and described with respect to one or implementations, those skilled in the art will think of equivalent variations and modifications based on the reading and understanding of this specification and the accompanying drawings. The present disclosure includes all such modifications and variations, and is limited only by the scope of the appended claims. In particular, with respect to the various functions performed by the above-mentioned components (such as elements, etc.), the terms used to describe such components are intended to correspond to any component (unless otherwise indicated) that performs the specified function of the component (such as it is functionally equivalent), even if the structure is not equivalent to the disclosed structure of the function in the exemplary implementation of the present disclosure shown herein. In addition, although the specific features of the present disclosure have been disclosed with respect to only one of several implementations, such features can be combined with one or other features of other implementations that may be desired and advantageous for a given or specific application. Moreover, insofar as the terms "including", "having", "containing" or their variations are used in specific embodiments or claims, such terms are intended to be included in a manner similar to the term "comprising".
[0073] The functional units in the embodiments of the present invention may be integrated into a processing module, or each unit may exist physically separately, or multiple or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. The above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc. The above-mentioned devices or systems may execute the storage method in the corresponding method embodiment.
[0074] To sum up, the above embodiment is an implementation mode of the present invention, but the implementation mode of the present invention is not limited by the embodiment. Any other changes, modifications, substitutions, combinations, and simplifications that deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.
Claims
1. A method for creating a Flutter container and a mini-program based on Android, characterized in that: The following steps are involved: Modify the Flutter SDK or customize the Flutter SDK to generate the mini-program installation files corresponding to each project and the main program installation files that support the running of the mini-programs; During runtime, the corresponding mini-program installation file is downloaded according to the user's operation, and then installed and run; Building a Flutter container includes: using Activity as a single Flutter container, pre-registering multiple Activities in the AndroidManifest manifest file in the main project, and specifying different processes; maintaining the relationship between the currently running mini-program and the container in the main project: when the main project receives an instruction to start a mini-program, first determine whether the mini-program is already in the running container. If so, directly start the corresponding container. If not, select one from the unstarted containers to start. After the new container is started, send a broadcast to the main program, and the main program updates the relationship between the currently running mini-program and the container; after miniAppActivity is started, create FlutterEngine, and start the mini-program name as needed, pass the corresponding libapp.so path to FlutterEngine in the form of FlutterShellArgs, so as to execute Flutter to load the corresponding mini-program code execution; Flutter container execution cache strategy: under normal circumstances, when the mini-program exits, the current process will be automatically killed when the Activity finishes to release resources. If it is set as a resident mini-program, the container will be kept in the background, and the container will be re-started at the next startup to achieve fast startup; Build a multi-process operating environment, use DartEntryPoint and window.defaultRouteName to determine the running mode of the mini program or APP, and schedule it.
2. The method for creating an Android-based Flutter container and applet according to claim 1, characterized in that: The modification of the Flutter SDK includes adding a new mini-program compilation instruction flutter build miniApp. The compilation process of the mini-program compilation instruction is as follows: Compile and generate installation files that support the main program APK and mini-programs; Modify the APK resource compilation process and remove the "package" path for mini-program resources; Modify the APK resource compilation process to support automatic decompression and repackaging of APK when compiling mini-program installation files.
3. The method for creating a Flutter container and a mini-program based on Android according to claim 1, characterized in that: The generation of the mini-program installation files corresponding to each project and the main program installation files supporting the mini-program operation includes: According to the configuration of the mini-program platform, pull the Flutter project code that needs to be packaged into a mini-program from the code repository and place it in the specified directory of the main project; Run the Flutter SDK customized command compilation in the root directory of the main project. This command will add each project in the mini-program directory to the pubsepc.yaml dependency of the main project in the form of a package, and then execute the main program Flutter apk building process. After the building is completed, the main program installation package is generated; After the main program is built, it will enter the project directory of each mini program in turn to first build the apk file of the mini program, and then decompress and extract the resource directory and libapp.so file to package them into the mini program installation package.
4. The method for creating a Flutter container and a mini-program based on Android according to claim 1, characterized in that: According to the user's operation, the corresponding mini-program installation file is downloaded, installed and run. The specific running process is as follows: The user selects the mini program they want to use in the mini program store. After clicking, the corresponding mini program installation file will be automatically downloaded from the background and the installation file will be verified; Start a new process and container, and specify the corresponding installation file to execute when FlutterEngine starts; Switch to the new interface, and after the mini program interface is rendered successfully, the user can operate it.
5. The method for creating an Android-based Flutter container and applet according to claim 1, characterized in that: The customized Flutter SDK includes automatically building the applet main project and container and automatically building the applet installation file: Automatically build the mini-program main project and container: When the build starts, the mini-program Flutter project in the specified directory will be automatically scanned, and package dependencies will be automatically added to the main project pubspec.yaml. Then all package dependencies of the main project will be analyzed, and possible version conflicts after merging multiple projects will be automatically handled. Android plug-in dependencies will be added to the main project, and resource files of each mini-program project will be copied to the main project. Switch to the root directory of the main project, start building the main project, and generate the main project apk file. Automatically build the mini-program installation file: Switch to the mini-program project directory, start building the mini-program project, and after generating the apk file, unpack it to obtain the aot file libapp.so and resource files, and re-sign and package them to generate the miniapp mini-program installation file.
6. The method for creating an Android-based Flutter container and applet according to claim 1, characterized in that: The DartEntryPoint determination method specifically includes: If running as a mini program, specify DartEntryPoint as a specific entry function when the container starts to create FlutterEngine. Based on the different entry functions, it can be determined whether the current operation is an app or a mini program.
7. The method for creating an Android-based Flutter container and applet according to claim 1, characterized in that: The window.defaultRouteName judgment method specifically includes: If running as a mini program, when the container starts to create FlutterEngine, set the specified parameters through setInitialRoute. After startup, in the Dart code, check whether window.defaultRouteName is "miniApp" to determine whether it is running in the mini program. If yes, it runs in the mini program.
Citation Information
Patent Citations
Cross-framework adaptation method for front-end development of mobile terminal
CN114546482A
Page displaying method and device, computer-readable storage medium and electronic device
US20220237254A1