Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

android - Getting Multiple dex error when using render script support lib

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       
 FilesJavajdk1.8.0_25injava.exe'' finished with non-zero exit value 2
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...