Fix Android Compile the 64K Reference Limit

Source: Internet
Author: User


A description of the 64k reference limit

Android application (APK) files contain executable bytecode files in the form of Dalvik executable (DEX) files, which cont Ain the compiled code used to run your app. The Dalvik executable specification limits the total number of methods that can is 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 1024x768 (or 2^10). Because 65,536 is equal to X 1024x768, this limit is referred to as the ' 64K reference limit '.

Getting past this limit requires the Configure your app build process to generate more than one DEX file, known as a< C0>multidex configuration.

Here's how to fix it

Versions of the platform prior to Android 5.0 (API level) with the Dalvik runtime for executing app code. By default, the Dalvik limits apps to a single Classes.dex bytecode file per APK. In order to get around this limitation, you canuse the "Multidex Support Library", which becomes part of the Primar Y 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-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 apps for Multidex.

Setting up your app development project to use a Multidex configuration requires so you make a few modifications to your App development project. In particular your 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 th E following code snippet:

Android {    compilesdkversion    buildtoolsversion "21.1.0"    defaultconfig {        ...        Minsdkversion        targetsdkversion ...        enabling Multidex support.        multidexenabled true    }    ...} dependencies {  compile ' com.android.support:multidex:1.0.0 '}

In your manifest add the class from the Multidex support library to the MultiDexApplication 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>


Fix Android Compile the 64K Reference Limit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.