I. INTRODUCTION
Some time ago, miui6 was launched in a great way. Because I didn't use Xiaomi's cell phone, I could only use other methods if I had a taste of miui6. At this time, I saw the application "Xiaomi system" in the App Store, after downloading it, we can see that this application is a light version of miui. An apk is packed with the following basic applications: Desktop, screen lock, and communication module (SMS, dial, and contact) cloud services and app stores have to admire Xiaomi's Internet product thinking after seeing this model. With this convenient promotion method, 91 assistants can download more than 500 kB of content, it is estimated that Xiaomi is too reluctant to go over the first complex patchrom project.
In fact, this apk merge method is not very difficult. I tried to write a demo, and the following briefly introduces the idea.
II. Packaging method
After the apk is installed, there are still two main project activity entries on the desktop.
2.1 eclipse tool packaging method
1. First, all the elements in the <application> </application> sub-tag of AndroidManifest. xml in the SecondaryApplication project are mentioned in AndroidManifest. xml in the MainApplication project. 2. Set SecondaryApplication to Is Library to true, and the path Is: Right-click-properties-android. 3. Set MainApplication project: Right-click-properties-android-Add SecondaryApplication project. 2.2 mk script packaging method
LOCAL_PATH: = $ (call my-dir) include $ (CLEAR_VARS) LOCAL_MODULE_TAGS: = optionalsecondaryapp_dir: = .. /SecondaryApplicationsrc_dirs: = src $ (secondaryapp_dir)/src # src_dirs: = srcres_dirs: = res $ (secondaryapp_dir)/res # LOCAL_SRC_FILES: = $ (call all-java-files-under, src) LOCAL_SRC_FILES: = $ (call all-java-files-under, $ (src_dirs) LOCAL_RESOURCE_DIR :=$ (addprefix $ (LOCAL_PATH)/, $ (res_dirs) LOCAL_AAPT_FLAGS: = -- auto-add-overlay -- extra-packages com. example. secondaryapplicationLOCAL_PACKAGE_NAME: = mainapplicationinclude $ (BUILD_PACKAGE) # Use the folloing include to make our test apk. include $ (call all-makefiles-under, $ (LOCAL_PATH ))
2.3 Multi-process or single process
The Xiaomi system apk packages so many applications that running in the same process will make the process very heavy, so although these applications are presented in the form of an apk, but they actually run in different processes. Currently, the activity, service, and other components of all applications are configured in an AndroidManifest. in the xml file, it is also very easy to determine how the activity and service run in different processes. You can configure this attribute:
Android: process = "com. example. secondaryapplication"
This option is configurable. If two applications are expected to run in the same process, ignore this attribute.
2.4.Application
Each android project can have an Application class, which is usually used to initialize some data of the Application. Assume that both projects have an Application class. In the first case, the two project configurations run in the same process. This method is easy to handle, you only need to put the initialization actions of the two projects in the Application class of the main project. The second case is that the two project configurations run in different processes, which makes the initialization process more troublesome, depending on the actual situation, you can modify the initialization action and put it in the Activity. You can think about it again.
Download DEMO project
Package two APKs into one and publish them.