As the company's business expands, the size of the App has also been increasing. Significant effects have been achieved through the past several App optimization optimizations. Conventional methods are now insufficient to reduce the size of the App any further. After analyzing the App, we found that some resources that are not frequently used and can be delivered, so we designed this SDK for dynamic resource loading.
- There are 3 built-in resources of predefined fonts, frame animations, SO, and 2 customizable resources such as single file and multiple files.
- Provides a common method for loading dynamic resources from which all resources can be loaded.
- Built-in resources, providing default application methods, external can be applied directly. Custom resources, users decide how to apply.
- For all resources, provide configurable packaging to reduce manual work.
By introducing a Dynamic Resource Management System, and dynamically packaging some .so files and other ordinary resources, the package size of the LalaMove client has been reduced from 54M to 46M, a decrease of 8M. Subsequent efforts will continue to explore ways of further dynamic packaging for other files.
Module | Function |
---|---|
sample_app | Demo's app module |
dynamic_res_plugin | Plugin module |
dynamic_res_base | Base module |
dynamic_res_core | Core module |
sample_native_lib | Demo's native library example |
dynamic_res_store | Generated resource folder |
dynamic_plugin.gradle | Plugin script |
-
Add dependencies to the module
classpath 'cn.huolala:dynamic_res_core:1.1.2'
-
Add dynamic_res_plugin as a dependency in your main build.gradle in the root of your project
classpath 'cn.huolala:dynamic_res_plugin:1.1.2'
-
Then you need to "apply" the plugin and add dependencies by adding the following lines to your app/build.gradle.
apply plugin: 'com.lalamove.dynamic_res_plugin'
Apply the plugin in your main build.gradle in the root of your project
apply from: 'dynamic_plugin.gradle'
-
Generate native library package
Add "dynamic_config" into dynamic_plugin.gradle learn more at the sample dynamic_plugin.gradle
-
Generate other resources package
Copy fonts, frame animations, and other resources to the path dynamic_res_store/input/
-
build application
The plugin will generate the resources in the dynamic_res_store/output/ directory.
-
Upload resources
Upload the resource to the server
-
Generate resource url ,fill into DynamicResConst.java
DynamicConfig config = DynamicConfig.Builder.with(context)
.executor()
.loadSoManager(createLoadSoManager())
.downlader()
.debugLog(BuildConfig.DEBUG)
.loggger()
.monitor()
.build();
DynamicResManager.getInstance().init(config);
learn more at the sample "DynamicInitJob.java"
IoThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
if (DynamicResManager.getInstance().getLoadSoManager() != null) {
DynamicResManager.getInstance().getLoadSoManager().loadSo(DynamicResConst.DEMO_SO, null);
}
});
learn more at the sample PreDynamicLoadJob.java
-
Font
DynamicResManager.getInstance().setTypeface(mFontTv, DynamicResConst.TypeFace.FONT_FZ_RZ_BOLD);
-
FrameAnimation
mCarAnim = DynamicResManager.getInstance().createFrameAnim(ImageView).durations(100).oneShot(false); mCarAnim.startAnim(DynamicResConst.FrameAnim.ANIM_CAR);
-
so
DynamicResManager.getInstance().getLoadSoManager().loadSo(DynamicResConst.DEMO_SO, new ILoadSoListener() { @Override public void onSucceed(String path) { mContentTv.append(new NativeLib().stringFromJNI()); } });
learn more at the sample MainActivity.java
- If you find a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
HUOLALA mobile technology team
Dynamic Plugin is released under the Apache 2.0 license. See LICENSE for details.