关于64k 引用限制的说明
Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files,
which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536—including Android framework methods, library methods, and methods in your
own code. In the context of computer science, the term Kilo, K, denotes
1024 (or 2^10). Because 65,536 is equal to 64 X 1024, this limit is referred to as the ‘64K reference limit‘.
Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as amultidex configuration.
解决方法如下
Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file
per APK. In order to get around this limitation, you can use themultidex
support library, which becomes part of the primary DEX file of your app and then manages access to the additional DEX files and the code they contain.
The Android plugin for Gradle available in Android SDK Build Tools 21.1 and higher supports multidex as part of your build configuration. Make sure you update the Android SDK Build Tools tools and the Android Support Repository to the latest version using the SDK
Manager before attempting to configure your app for multidex.
Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:
- Change your Gradle build configuration to enable multidex
- Modify your manifest to reference the
MultiDexApplication
class
Modify the module-level build.gradle
file configuration to include the support library and enable multidex output, as shown in the following code snippet:
android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { ... minSdkVersion 14 targetSdkVersion 21 ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.0' }
In your manifest add the MultiDexApplication
class
from the multidex support library to the application element.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application> </manifest>