In Android development , the function method exceeds the 65k limit, we often use the Multidex sub-package solution, but multidex configuration, the system apk build, signature, packaging complexity greatly increased, seriously reduced the construction efficiency. How do we deal with this problem?
To solve this problem, we usually use a new development flavor and production flavor in Gradle productflavors to meet our different building needs.
To show you more intuitively how to do this, let's demonstrate how to set these flavors in the Gradle build file with an example:
Android { productflavors { //Define Separate Dev and prod product flavors. dev { & nbsp //Dev utilizes minsdkversion = <span class= "Hljs-number" >21</ Span> to allow the Android gradle plugin / /to Pre-dex per module and produce an APK, can be tested ON&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NB sp; //Android Lollipop without time consuming Dex merging processes. & nbsp; minsdkversion <span class= "Hljs-number" >21</span> } prod { //The actual minsdkverSion <span class= "Hljs-keyword" >for</span> the application. minsdkversion <span class= "Hljs-number" >14</span> } } <span class= "Hljs-keyword" >...</span> buildtypes { Release { Runproguard true ProguardFiles Getdefaultproguardfile (<span class= "hljs-string" > ' proguard-android.txt ' </span>), <span class= "hljs-string" > ' Proguard-rules.pro ' </span > } }} dependencies { Compile <span class= "hljs-string" > ' com.android.support:multidex:1.0.0 ' </span>}
After you have completed the configuration changes to the injury, you configure Productflavor and BuildType to use the Devdebug variant app. With these variant apps, you can set Proguard Disable, Multidex enable for easy testing.
These configurations require the following actions for the Android Gradle plugin:
1. Before subcontracting, each module in the compiled application includes a dependent project, which is called pre-dexing.
2. Include each of the Dex files.
3, most importantly, for the main Dex file, will not do segmentation to ensure that the calculation speed.
This setting ensures that our final report is a multidex mode without affecting the efficiency of the tests we develop.
Android Studio use variant apps in
It is very convenient to build variant apps using the Multidex tool. The Android Studio allows us to choose the interface for this variant build method.
Building a Variant app using Android studio to build "Devdebug" requires two steps:
1. Open the Variant edit window and select the Favorites option.
2. Click to compile different variants as shown in
The above is the Android Compatibility Pack Multidex development and construction of specific methods, I hope that everyone in the use of Multidex help.
Related reading: "Talk about how Android prevents APK programs from being recompiled "
How to develop and build Android Compatibility Pack Multidex