| Start |
|---|
| Enabling Multidex In order to enable a multidex configuration you need:
Gradle configurationIn Enable MultiDex in your ApplicationThen proceed with one of three options:
When these configuration settings are added to an app, the Android build tools construct a primary dex (classes.dex) and supporting (classes2.dex, classes3.dex) as needed. |
| Multidex by extending Application Use this option if your project requires an Specify this In the Ensure that the |
| Multidex by extending MultiDexApplication This is very similar to using an However, using this method, you don't need to override Extend Add this class to your AndroidManifest.xml exactly as if you were extending Application: |
| Multidex by using MultiDexApplication directly Use this option if you don't need an This is the simplest option, but this way you can't provide your own For this option, simply specify the fully-qualified class name |
| Counting Method References On Every Build (Dexcount Gradle Plugin) The dexcount plugin (opens new window) counts methods and class resource count after a successful build. Add the plugin in the Apply the plugin in the Look for the output data generated by the plugin in: ../app/build/outputs/dexcount Especially useful is the .html chart in: ../app/build/outputs/dexcount/debugChart/index.html RemarksWhat is dex?Dex is the name of the file format and encoding to which Android Java code is compiled. Early versions of Android would load and execute Dex is a very old file format, in terms of the lifespan of smartphones, and was designed for devices whose main memory was measured in tens of megabytes. The design limitations of those days have remained with us to this day. The problem:The What to do about it:Google has provided a way around this problem, called Multidex. It has compile-time and run-time components. As its name implies, at compile-time it will divide code between one or more This approach works well on newer devices, but has some substantial drawbacks. It can increase application startup time dramatically, and on older devices can cause Multidex, while effective, should be avoided if possible. How to avoid the limit:Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries. The following strategies can help you avoid hitting the dex reference limit:
The first point requires diligence and discipline on the part of the developer. When incorporating third-party libraries, one must consider the size of the library. For example, two popular JSON libraries are Jackson and Gson. Functionally they are quite similar, but Gson tends to see greater use in Android. One reason is that Jackson weighs in around 9,000 methods, whereas Gson contributes 1,900. There are several tools available to help developers keep track of the size of their application:
|
Read Article
https://develop.horje.com/learn/1434/reference