Android: My Application Is Too Large and Gives "Unable to Execute Dex: Method Id Not in [0, 0Xffff]: 65536"

Unable to execute dex: method ID not in [0, 0xffff]: 65536

Update 3 (11/3/2014)
Google finally released official description.


Update 2 (10/31/2014)
Gradle plugin v0.14.0 for Android adds support for multi-dex. To enable, you just have to declare it in build.gradle:

android {
defaultConfig {
...
multiDexEnabled true
}
}

If your application supports Android prior to 5.0 (that is, if your minSdkVersion is 20 or below) you also have to dynamically patch the application ClassLoader, so it will be able to load classes from secondary dexes. Fortunately, there's a library that does that for you. Add it to your app's dependencies:

dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}

You need to call the ClassLoader patch code as soon as possible. MultiDexApplication class's documentation suggests three ways to do that (pick one of them, one that's most convenient for you):

1 - Declare MultiDexApplication class as the application in your AndroidManifest.xml:

<?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>

2 - Have your Application class extend MultiDexApplication class:

public class MyApplication extends MultiDexApplication { .. }

3 - Call MultiDex#install from your Application#attachBaseContext method:

public class MyApplication {
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
....
}
....
}

Update 1 (10/17/2014):
As anticipated, multidex support is shipped in revision 21 of Android Support Library. You can find the android-support-multidex.jar in /sdk/extras/android/support/multidex/library/libs folder.


Multi-dex support solves this problem. dx 1.8 already allows generating several dex files.

Android L will support multi-dex natively, and next revision of support library is going to cover older releases back to API 4.

It was stated in this Android Developers Backstage podcast episode by Anwar Ghuloum. I've posted a transcript (and general multi-dex explanation) of the relevant part.

Dex Loader] Unable to execute dex: method ID not in [0, 0xffff]: 65536 Size Exceed

My answer is matched with the answer of this following question, his answer give me final solution.

Shrink Google Play Service

Who give negative vote of my question, please see this link and try to build up yourself like him. :)

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 in android studio

Android has a pre-defined upper limit of Methods of 65536.

The most common cause of this is using the full google play services library, instead of just the subset you need, eg design, cardview, maps etc.

If this is not the case, then use the multidex library, which enables a bigger limit.
See here:
http://developer.android.com/tools/support-library/features.html#multidex

Basically just this in gradle:

com.android.support:multidex:1.0.0

Android: my application is too large and gives Unable to execute dex: method ID not in [0, 0xffff]: 65536?

You can also develop one or more of these as a plugin to your main app, in the form of a separate APK available for download. That APK would expose some component that the main app would use -- since I do not know the nature of your integration with these services, I cannot make a more specific recommendation about that. You would use your own signature-level custom <permission> to secure communications between the two apps. And, as a bonus, if using the third-party library adds requirements for additional permissions, you would only need those permissions in the plugin APK, keeping your main APK smaller.

method ID not in [0, 0xffff] build error

According to Android developer documentation:

If you have built an Android app and received this error, then congratulations, you have a lot of code! This document explains how to move past this limitation and continue building your app.

Sometimes, importing libraries using gradle dependency can lead to this error. Is there google play services library in your app? If any, instead of compile com.google.android.gms:play-services:9.4.0, you can import libraries that you only want to use for example if you want to use google map, just import com.google.android.gms:play-services-maps:9.4.0 instead com.google.android.gms:play-services:9.4.0. It will help reducing the number of dex generated. You also can use proguard to eliminate unused code.

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

You can refer to Android Guide on how to selectively compiling APIs into your executable



Related Topics



Leave a reply



Submit