Build errors from referencing more than 65,000 methods
If you submit an app to the Amazon Appstore that references close to 65,000 methods, you may receive the following error message via email or on the App Status screen after submission:Additional methods added from Amazon’s wrapper
Amazon wraps every app in the Amazon Appstore with code to provide developers with various reports, analytics, DRM, and app updates. This wrapper adds 1,627 additional referenced methods for the Amazon library and 9 additional methods per activity. Because of these additional referenced methods, your app could be pushed over the method limit if it references close to 65,000 methods. Although this limit has always existed, exceeding the method-reference limit has become more common with the release of Android 5.0 (Lollipop), which includes new features that often increases the number of method references an app might make. To avoid this limit, considering counting the number of method references and reducing the number of references in your app.Counting the number of method references
To count the number of the methods that your app references and what part of the app references them, you can use the dex-method-counts tool available from GitHub: https://github.com/mihaip/dex-method-counts.Reducing the number of method references
To reduce the number of method references, try removing as many extra libraries and methods as possible. Alternately, you can use ProGuard with-dontoptimize –dontobfuscate in the configuration, which will remove unused methods from the dex file at build time.
If the these approaches do not work for your app, try using the multi-dex approach, which splits up classes.dex into multiple dex files.
You can use the multidex library with the Android Gradle plugin. For more information, see Enable multidex for apps with over 64K methods.
Note the following with the multidex approach:
- You must use Gradle for your Android development.
- You might find that Multidex does not remove enough methods without performing a few extra steps (outlined in the next section).
classes.dex file.
Using the multidex library
With Android 5.0 Lollipop, a support library (calledandroid-support-multidex.jar) appeared in Android SDK ver 21.1.x and Android Support library 21.0.3. You can find this support library in \android-sdk\extras\android\support\multidex\library\libs. It contains two new classes — MultiDex and MultiDexApplication — and simplifies the multidex loading process.
You do not need to use this library if your app targets Android 5.0 exclusively because Android 5.0 has built-in support for secondary dex files. On previous versions, however, Android adds additional .dex files from the APK archive to the classloader. The library allows the archive to become part of the primary DEX file of your app and manages access to the additional DEX files. As a result, you should use this library if your app targets any Android releases before Android 5.0.
To implement this solution for pre–Android 5.0 apps:
- Make sure you have updated your Android Build Tools to the latest version. You will need at least version 21.1.x or later.
-
Add the
android-support-multidex.jarlibrary into your project. You can find it in\android-sdk\extras\android\support\multidex\library\libs. -
Add
multiDexEnabled trueand a Multidex dependency to yourbuildConfigin thebuild.gradlefile, as shown in the following example: -
Either override the
android.app.Applicationclass, or declare theMultiDexApplicationclass in theAndroidManifest.xmlfile, as shown in the following code: -
If you have any additional libraries in your project, be sure that you disable pre-dexing on them. Unfortunately, the
--multi-dexoption is not compatible with pre-dexed libs. You can disable pre-dexing by adding the following code to yourapp/build.gradlefile: -
Configure your build instructions to ensure that your multidex app is optimized for the Amazon Appstore and the submission process. You have two options:
-
Manually create the
main-dex-listfile. In app/build.gradle file, add the following:This code uses two parameters:--multi-dex— enables splitting mechanism in build process.--main-dex-list— file with list of classes which have to be attached in main dex file.
--main-dex-listparameter to put the following in the main.dexfile:- Custom Applications
- Activities
- Services
- Receivers
- Providers
- Instrumentations
- Annotations
-
Ignore the
multi-dexandmulti-dex-listparameters if you are using studio 0.9.0+ gradle 0.14.2 and let the build tools automatically limit thedx.additionalParametersparameter to60,000. This should work for most applications; however, if you have a very large number of classes in your app, you might find that you will need to manually set your max number to less than 60,000 to have your app pass submission to the Amazon Appstore properly.
-
Manually create the
Keeping the AndroidX library unobfuscated
If you’re using AndroidX library for multidexing, keep the AndroidX library unobfuscated in your code by adding this line to your Proguard file:Additional resources
For assistance in generating themain-dex-list, see the following::
- CreateManifestKeepList.groovy — this is the source code for how Gradle automatically generates a
main-dex-list. - A tool that can automatically generate this main-dex-list.

