2

I am using render script in support library in my gradle file.

  renderscriptTargetApi 22
  renderscriptSupportModeEnabled true

After I added these 2 lines, I am getting this error

at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:    
org.gradle.process.internal.ExecException: Process 'command 'C:\Program       
 Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
chathura
  • 3,362
  • 6
  • 41
  • 68

4 Answers4

8

I've had similar issue. Try add to your gradle file

multiDexEnabled true

just to be sure you are not exceeding the 65K methods dex limit imposed by Android (Java finished with non-zero exit value 2 - Android Gradle). If you are using some other android-support libraries like appcompat or design or support-v4/v7... add another line to your gradle file

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

Renderscript library already includes support-annotations library, which then may collide with those other support libraries, I suppose. Anyway, these gradle commands fixed it for me.

Edit: It was supposedly fixed in 23.1.0 revisions of Android support libraries, therefore after updating to 23.1.0 you'd need to remove that all*.exclude command. Otherwise your app would not compile due to missing support-annotations library.

Community
  • 1
  • 1
2

https://code.google.com/p/android/issues/detail?id=181697 is the bug for this, along with a temporary workaround.

Stephen Hines
  • 2,612
  • 1
  • 13
  • 12
  • The solution is to manually delete the annotation classes in jar. I am using android studio and those libraries are located in "External Libraries". How to delete those classes in android studio? – chathura Aug 19 '15 at 05:06
0
  dexOptions {
  preDexLibraries = false
}

In your build.gradle file try adding the following block inside your android block.

RamBabu Pudari
  • 912
  • 7
  • 19
0

Use

 renderscriptTargetApi 18
 renderscriptSupportModeEnabled true
Settembrini
  • 1,366
  • 3
  • 20
  • 32
  • 1
    This requires that your minimum sdk version (minSdkVersion) be 18 as well. This did not work for me since I require minSdkVersion 17. – Ray Hunter Aug 27 '15 at 05:58