Gradle - Unexpected Top Level Exception - Out of Nowhere

Pretty sure gradle for me. He started a project that works just a few days ago. Updated Android studio and reopened the project. I have tried everything I can think of, from deleting / updating libraries checking xml files and structure. Removing the gradle cache and installing the latest jdk seems to help nothing.

Also tried adding:

configurations { all*.exclude group: 'com.android.support', module: 'support-v4' } 

Link to other posts in stackoverflow

I exported the error from the console, and it looks like this:

 objc[2338]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501) at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276) at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) :Derp:dexDerpDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':Derp:dexDerpDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Applications/Android Studio.app/sdk/build-tools/19.1.0/dx --dex --num-threads=4 --output /Users/MorePathStuffForALongWhile Error Code: 2 Output: objc[2338]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. 
+6
source share
3 answers

Your problem: you went ok. 65000 when compiling the application. You should find a way to reduce the number of methods in your application.

If you use Google Play Services, you can try this method to compile it in more detail.

If not, you can just use multiDex (be sure to use the latest version of Android Studio). Use this in the build.gradle file:

 android { defaultConfig { ... multiDexEnabled = true } } 
+1
source

If you are using gson or jackson, try removing its dependencies. It worked for me. compile 'com.google.code.gson:gson:2.1

0
source

In the source code +, all included libraries end with definitions of more than 65 thousand methods. This is currently a dex restriction limitation .

To avoid this situation, multidex support was introduced . The compilation time of the output classes is split and merged into several dex files. And at runtime, they are loaded from multiple dex files.

To do this, you need to add multidex support:

 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' } 

And set the application class extending MultiDexApplication .

0
source

Source: https://habr.com/ru/post/970887/


All Articles