Problem with DexIndexOverflowException after updating to the latest application library and support

I use the following settings through gradle :

 compileSdkVersion 21 ANDROID_BUILD_MIN_SDK_VERSION=14 ANDROID_BUILD_TARGET_SDK_VERSION=21 ANDROID_BUILD_TOOLS_VERSION=21.0.2 ANDROID_BUILD_SDK_VERSION=21 

I also have the following settings in the gradle file:

 compile 'com.android.support:support-annotations:21.0.0' compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.android.support:support-v4:21.0.0' 

I always get UNEXPECTED TOP LEVEL EXCEPTION error.
But when I do 21.0.0 to 20.0.0 , it works fine ... but I canโ€™t access any of the Android 21 API options. Am I doing something wrong here? How can I compile it without this exception? I don't have support cans anywhere else outside of other class projects (facebook, etc.).

Here is the full stack trace:

 UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283) at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302) at com.android.dx.command.dexer.Main.run(Main.java:245) at com.android.dx.command.dexer.Main.main(Main.java:214) at com.android.dx.command.Main.main(Main.java:106) 
+71
android android-5.0-lollipop build.gradle gradle android-support-library
Oct 22 '14 at 19:19
source share
7 answers

This post looks like your project is too big.

You have too many methods. There may be 65536 methods for dex .

Since the gradle plugin 0.14.0 and Build Tools 21.1.0 you can use multidex support .

Just add these lines to build.gradle :

 android { defaultConfig { ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.1' } 

Also in 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> 

If you use your own Application class, change the parent class from Application to MultiDexApplication .

+146
Oct 22 '14 at 19:47
source share

1) add a dependency to the build.radio.exe file of the application

 compile 'com.android.support:multidex:1.0.2' 

2) If you do not override the application class, edit the manifest file to set the android: name name in the tag as follows:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:name="android.support.multidex.MultiDexApplication" > ... </application> </manifest> 

If you override the Application class, modify it to extend MultiDexApplication (if possible) as follows:

 public class MyApplication extends MultiDexApplication { ... } 

Or, if you override the application class but cannot change the base class, you can instead override the attachBaseContext () method and call MultiDex.install (this) to enable multidex:

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

3) Add multidex support to defaultConfig in build.gradle

 defaultConfig { ... minSdkVersion 16 targetSdkVersion 26 ... // Enabling multidex support. multiDexEnabled true } ... 
+45
Jun 05 '15 at 7:30
source share

Before you mess with MultiDex

This solution is either too large (use MultiDex), or you are compiling and incorporating some unnecessary things into your project. I have a problem with my tiny project. Here is what I did to fix this:

I removed this from build.gradle :

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } 

And I manually deleted the file folder from the root of the application. The problem is fixed.

+3
Jun 13 '16 at 2:53 on
source share

Follow this 65K workaround guide.

I solved this problem in gradle by setting multiDexEnabled true and expanding my application with class MyApp extends MultiDexApplication

+2
Jan 18 '15 at 22:32
source share

I just commented on the compilation of filetree(include: ['*.jar'], dir: 'libs') in the build.gradle file (as suggested above) and rebuilt the project. Compiled without errors. I did not need to move folders.

0
Sep 07 '16 at 3:57
source share

First make sure app/build.cradle enabled in app/build.cradle build.cradle:

 buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.config } debug { signingConfig signingConfigs.config } } 

If this does not solve the problem, enable multidex build for your application.

0
Nov 17 '16 at 11:43
source share

I ran into this problem when I put together the entire package of Google Play APIs in my application. I solved the problem using a custom API.

For example, to enable only the Google Fit and Android Wear APIs, replace the following line in the build.gradle file:

 compile 'com.google.android.gms:play-services:11.0.2' 

with these lines:

 compile 'com.google.android.gms:play-services-fitness:11.0.2' compile 'com.google.android.gms:play-services-wearable:11.0.2' 

The problem is explained in the following link .

0
Jul 17 '17 at 10:32
source share



All Articles