Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - Unexpected top-level exception - Out of nowhere

Fairly certain gradle is out for me. Started a project that has been working fine just a few days ago. Updated android studio and opened the project again. I have tried everything I can come up with, from removing/updating libraries checking xml-files and structure. Removing gradle cache and installing latest jdk, nothing seems to help here.

Also tried to add:

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

Refered in other posts on 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.
like image 793
Hiam Avatar asked Jun 16 '14 07:06

Hiam


1 Answers

Your problem: You've passed the approx. 65000 method limit when compiling the app. You must find a way to reduce the number of methods in your app.

In the case that you are using Google Play Services, you can try this method to compile it with more granularity.

If not, you can simply use multiDex (make sure that you are using a recent version of Android Studio). Use this in your build.gradle file:

android {
    defaultConfig {
        ...
        multiDexEnabled = true
    }
}
like image 84
webo80 Avatar answered Nov 05 '22 16:11

webo80