Hot Article Guide | Click Title to Read
How to Level Up in the Job-Hopping Season of September and October to Find a Suitable and Satisfying Job?
Either Work Hard or Resign, Never Just Drift Along
“I have been with the company for 6 years, but it took only 6 minutes to let me go”
Author: Dotry
Link:https://www.jianshu.com/p/57cccc680bb6
A new technology that is crucial for the future development of Android: the official dynamic solution, which is disruptive~
It is strongly recommended to read the official article first:
-
Why it is said to be very important for the future development of Android
-
Google’s official pluginization solution—A new dynamic framework analysis of Android App Bundles Seasoninthesun
At this year’s Google I/O conference, Google introduced a new App dynamic framework (Android App Bundle, abbreviated as AAB) to Android. AAB achieves dynamic loading through Split Apk, and using the AAB dynamic delivery method can significantly reduce application size.
Now, just build an application (app bundle) in Android Studio, and you can cover all the content needed for the application (suitable for all devices): all languages, all device screen sizes, all hardware architectures. It does not support dynamic delivery itself; it is just a carrier file for dynamic delivery, and the real implementation logic is not it.
1. Split APKs:
Multi-apk supports the following types of screen density ABI, using a new splitting mechanism to build hdpi and mdpi versions of the same application, which can share many tasks (such as javac, dx, proguard). In addition, it will be regarded as a single variant, and the same test program will be used to test each multi-APK.
2. Dynamic Feature Module:
This concept feels like downloading resources only when entering a new map in a game, rather than downloading all resources at once. This makes the apk smaller, and just like game logic, if a novice can’t access the advanced dungeon map, there is no need to download that part of the content. Some users may not use certain features for a long time, so they can be placed in the dynamic feature module and downloaded when needed.
Below is a diagram showing the effect of Dynamic Delivery:
(Left) Old APK delivery example – delivering all resources to the device; (Right) Dynamic delivery example – only delivering necessary resources to the device
For specific instructions and video demonstrations, please visit the website
-
https://developer.android.com/guide/app-bundle/
Benefits:
Smaller Size 【My personal understanding is that it feels smaller relative to the user】
Google has claimed that it can reduce app sizes by up to 50 percentIts own apps like YouTube and other apps like LinkedIn saw a 23% file reduction
Faster Installation 【base.apk is optimized and will install faster】
Supports dynamic release
Limitations
-
Only for apps released through Google Play, (Google further consolidates its ecosystem)
-
Need to join Google’s beta program
-
Minimum supported version Android 5.0 (API level 21)
-
Versions below Android 5.0 (API level 21) will have their size optimized by Google Play, but dynamic delivery is not supported.
Costs
-
Need to upgrade to Android Studio 3.2 to modify the project to support App Bundle format
-
Integrate Play Core Library
2. Principles
Combining Google Play Dynamic Delivery to achieve dynamic functionality
Android App Bundle supports modularization, through Dynamic Delivery with split APKs, splitting an apk into multiple apks, loading on demand (including loading C/C++ libraries), so developers can deliver functions on demand at any time, rather than just during installation.
-
Base Apk is the apk installed for the first time, containing common code and resources, so other modules are based on Base Apk
-
Configuration APKs contain native libraries and resources adapted to the current phone screen resolution
-
Dynamic feature APKs are modules that do not need to be loaded at the first installation
The specific structure is as follows:
3. Usage
When using it, add a new module in Android Studio – Dynamic Feature Module.
Select Dynamic Feature Module and directly next to the following page
-
Enable on-demand: whether to support on-demand download mode. If not supported, then the feature will be installed when the app is installed.
-
Fusing: If the app runs on Android 5.0 (excluding 5.0) or below, checking Fusing indicates that the feature will be packaged into the complete apk.
-
Module Title is used by the platform to identify the module to the user when confirming whether the user wants to download the module.
The project structure diagram generated by the new project is as follows:
The feature generated directory structure is not much different from our commonly used module structure.
For example, the demo project structure provided by Google is as follows:
In the demo, there are four features, and the module names clearly indicate that these features are examples of how to access code, resources, so on.
We can see that the source code mainly uses a SplitInstallManager class to manage different modules.
Below is a simple usage for loading corresponding modules:
The plugin com.android.dynamic-feature used for compiling dynamic feature modules generates apk files in the build directory of all dynamic feature modules after running the example.
After running, we can open the directory under feature to check as follows:
It can be found that an apk file will be generated, and this apk file is called by base.apk.
Then decompile base.apk, and two phenomena can be found:
-
All dynamic feature module’s code, resources, so are not packaged in the main apk.
-
The main apk manifest includes the manifest of all dynamic feature modules, i.e., feature manifest will be merged into the main apk manifest.
These two phenomena require us to plan well when dividing modules. As the requirements continue to iterate, structural planning may need to be adjusted accordingly.
-
Build Bundle(s) Android App Bundle: provides a new compilation product format file aab, using the App Bundle provided by Android Studio.
Generation method is as follows:
1. Generate via command line, input the following command in the command line:
./gradlew :base:bundleDebug
2. Generate via Android Studio
After clicking “Build Bundle(s)”, we will generate the bundle.aab file in the main project’s build directory. This file is a compressed format file, and the contents of this aab file are as follows:
From the content of the aab file, it can be seen that it contains the code, resources, so of base and feature, as well as a BundleConfig.pb configuration file, which is used by Google Play to split the apk. If we need to support dynamic release on Google Play, we only need to upload the aab file, and the subsequent work will be handled by Google Play.
4. Test Android Application Package with Bundletool
Use the bundletool command line tool locally:
Download the bundletool tool from GitHub
-
https://github.com/google/bundletool/releases
Executing java –jar bundletool.jar can convert the “.aad” file into an “apks” file.
For example, generate a bundle.aab file above, use the command to generate a bundle.apks file
java -jar bundletool.jar build-apks –bundle=bundle.aab –output=bundle.apks –ks=features.jks –ks-pass=pass:tcl123 –ks-key-alias=key0 –key-pass=pass:tcl123
Execute the installation command:
java -jar bundletool.jar install-apks –apks=bundle.apks
[Currently there seems to be a bug in Windows 10]
For the configuration of command parameters, please refer to the table below:
Get link device information, the command is as follows:
java -jar bundletool.jar get-device-spec –output=tcl.json –adb=D:/Android/SDK/platform-tools/adb.exe
After splitting the apks file, we will generate the following apk.
The command is as follows:
java -jar bundletool.jar extract-apks –apks=bundle.apks –output-dir=D:\bundle\apks –device-spec=tcl.json
This also proves that our generated .aad file is correct.
If you want to join Alibaba, quickly join our Knowledge Planet, as shown below:
If you have good articles to share with everyone, please feel free to submit them directly to me.
Finally, the National Day benefits are here. Our Knowledge Planet has reached 1000 people. As previously stated, the price will greatly increase to 169 yuan when it reaches 1000 people. In order to thank everyone for their attention and support, we will maintain the current price of 99 yuan for the last day. After today (midnight 00:00), the price will rise to 169 yuan. Welcome everyone to join our Knowledge PlanetFor more information about the planet, see:
How to Level Up to Become a Java and Android Architect?
How to Level Up in the Job-Hopping Season of September and October to Find a Suitable and Satisfying Job?
Say Two Things
Scan the WeChat QR code or click the QR code above to receive advanced resources for Android, Python, AI, Java, etc.
For more learning materials, click the “Read Original” below to get them