6

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.
Hiam
  • 303
  • 1
  • 4
  • 12
  • 2
    possible duplicate of [Unable to execute dex: method ID not in \[0, 0xffff\]: 65536](http://stackoverflow.com/questions/15209831/unable-to-execute-dex-method-id-not-in-0-0xffff-65536) – Scott Barta Jun 16 '14 at 13:22
  • I don't think the problem that Hiam has described is captured by the link you have provided Scott Barta. – sudocoder Jul 11 '14 at 14:56
  • Did you move to Dagger 1.2.2? I got this changing only my Dagger dependency from 1.1.x to 1.2.2. Though looks possible it is a "too many methods in Android app" based on other search results. – Colin M. Sep 18 '14 at 23:32
  • As response, I'm fairly certain it was the "too many methods" error :) – Hiam Apr 08 '15 at 12:46

3 Answers3

1

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
    }
}
webo80
  • 3,365
  • 5
  • 35
  • 52
0

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

tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
Nguyen Viet
  • 109
  • 1
  • 2
0

Your source code + all included libraries end up with more than 65k method definitions. This is currently a limitation of dex.

In order to avoid this situation, multidex support was introduced. A compile time the output classes are split and bundled in multiple dex files. And at runtime they are loaded from multiple dex files.

To achieve 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 an Application class extending MultiDexApplication.

S.D.
  • 29,290
  • 3
  • 79
  • 130