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
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.
https://code.google.com/p/android/issues/detail?id=181697 is the bug for this, along with a temporary workaround.
dexOptions {
preDexLibraries = false
}
In your build.gradle file try adding the following block inside your android block.
Use
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
Related
I have two libs in my gradle file that require slf4j. Pusher and Gimbal. Both of these jars have slf4j in them. So even when I tell gradle to ignore them (multiDexEnabled true) I still receive a namespacing error.
Does anyone know how to fix this?
com.android.dex.DexException: Multiple dex files define Lorg/slf4j/impl/StaticLoggerBinder;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
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.mergeDexes(DexMerger.java:171)
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 '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
The error I receive with (multiDexEnabled true):
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
>java.util.zip.ZipException: duplicate entry: org/slf4j/helpers/BasicMarker.class
Multidex solves a very different problem from the one you describe. Multidex fixes the issue of being limited to ~65,000 methods per dex file. You can find the documentation for multidex here.
Instead, what you want to do is exclude sl4j from one of your libraries, here's an example of what that might look like, depending on what dependencies are causing the issue:
compile ('com.example.library:library-with-sl4j:1.0') {
exclude group: 'org.sl4j', module: 'sl4j-simple'
}
You will have to identify which library is causing the issue and which sl4j module you need to exclude.
Ideally you would inform the library author(s) using older versions that they should update so that all your dependency are using the same (latest) version.
I have imported project from Eclipse to Android studio. It builds successfully, but when I try to execute the project in android studio I am getting following exception .
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple
dex files define Landroid/support/annotation/AnimRes; at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
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.mergeDexes(DexMerger.java:171) at
com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at
com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at
com.android.dx.command.dexer.Main.run(Main.java:246) at
com.android.dx.command.dexer.Main.main(Main.java:215) 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_45\bin\java.exe'' finished with
non-zero exit value 2
And here is my Build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.heal4me_app"
minSdkVersion 11
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/android-support-v13.jar')
}
I have tried all the posted solution for the above problem, which is available on stackoverflow. But I couldn't find any right answer for this problem.
I had the same issue after adding the library com.amazonaws:aws-java-sdk:1.8.0 to my gradle dependencies. After removing the dependencie, everything seems to be fine. I don't know why, if I find a solution I report it.
After the many efforts I have to finally do the hard work to migrate from eclipse to android studio.
I have copied all the java classes and xml file one by one to the android studio. And finally I am done. I think this is not the good solution but I have to do this compulsorily to resolve above error.
I have read so many blogs and stackoverflow questions regarding this issue. but unfortunately that didn't help me, that's why I have to come up with this hard work.
I updated Android Studio to the latest version, and let it "fix the project" and the like - but now my project does not compile, gives me
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
However, this isn't resolved by just multidexing, because when I added this:
defaultConfig {
...
multiDexEnabled = true
}
This happens
D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --multi-dex --main-dex-list D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\multi-dex\debug\maindexlist.txt --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
3
Output:
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.android.dx.cf.code.ConcreteMethod.makeSourcePosistion(ConcreteMethod.java:254)
at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:306)
at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:367)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
at com.android.dx.command.dexer.Main.processClass(Main.java:729)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:82)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332)
at com.android.dx.command.dexer.Main.run(Main.java:243)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
I tried changing the build tools to latest
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
Because by default it changed to 20.0.0 which seemed to use the SDK for 4.4W, but this didn't fix my problem.
Does anyone know what could be wrong here?
EDIT:
Changing the build tools or the compile SDK did not fix the problem.
Turning the app into a multi-dex project and also adding the following
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
...
multiDexEnabled true
}
...
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
Fixed the build process, however this still seems to be just a "treatment" but not a fix to the problem.
I am not sure if this is related, but this is my dependency list:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.squareup:otto:1.3.5'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.7.1'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.madgag.spongycastle:core:1.51.0.0'
compile 'com.madgag.spongycastle:prov:1.51.0.0'
compile 'com.madgag.spongycastle:pkix:1.51.0.0'
compile 'com.google.code.gson:gson:2.3'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('com.googlecode.json-simple:json-simple:1.1.1') {
exclude module: 'junit'
}
compile 'com.google.android.gms:play-services:6.5.87'
}
The only new dependency since then has been the last line, which I added as per https://developer.android.com/google/gcm/client.html so I don't think that is the source of the problem.
EDIT2:
Yes, it was the source of the problem. As I needed Google Cloud Messaging, I replaced that dependency with the base as per http://developer.android.com/google/play-services/setup.html#split :
compile 'com.google.android.gms:play-services-base:6.5.87'
And it fixed the problem. Thank you for the help.
EDIT3:
As of play services 7.0.0, the GCM is in
compile 'com.google.android.gms:play-services-gcm:7.0.0'
EDIT4:
Play Services updated to 7.3.0.
Please keep check of the latest version here: http://developer.android.com/google/play-services/setup.html#split
The error means you have reached maximum method count in your app. That does include any libraries that you use for your project.
There are two ways to tackle the issue:
Get rid of any third-party libraries that you don't really need. If you use google play services that might contribute a lot to the method count. Fortunately as of the latest play-services release it is possible to include only parts of the framework.
Use a multi dex setup for your application.
I am phasing these problem & in my case used these link to overcome that error successfully..!!!
The DEX 64k limit is not a problem anymore, almost
To sum it up, adding multidex support:
In case of
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
Google decided to release an official solution for this in the form of the MultiDex Support Library.
dependencies {
...
compile 'com.android.support:multidex:'
...
}
Then enable multi-dexing by setting the multiDexEnabled flag in the buildType or productFlavor section of your gradle configuration.
defaultConfig {
...
multiDexEnabled true
...
}
Then depending on your project, you have 3 options:
If you haven’t created your own Application class, simply declare android.support.multidex.MultiDexApplication as your application class in AndroidManifest.xml
....
android:name="android.support.multidex.MultiDexApplication"
...
If you already have your own Application class, make it extend android.support.multidex.MultiDexApplication instead of android.app.Application
If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:
public class MyApplication extends FooApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Your compilation process might run out of memory.
To fix it, set the following dex options in the ‘android’ closure –
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
More to know about multidex is here: http://developer.android.com/tools/building/multidex.html
Another link which becomes helping to solve a these error : Referance Link
I am a new Android Developer and build files always scare me. :D
I am using some third part libraries in the project
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
}
In addition to this I am also using MPAndroidChart(the only jar in the lib folder) which is only available as a jar file and not a gradle dependency.
MPAndroidChart uses NineOldAndroids as a dependency and I suspect one of my other libraries also uses it and it is causing a build fail.
Any idea how to make both these libraries behave?
I checked the similar questions and found one that was exactly my problem-
Gradle error - Execution failed for task ':app:dexDebug'
But he was including the NineOldAndroids library on his own. So he just removed that line and it was working.
One idea that I had was to strip apart the jar and include them as java files in my project, but that seemed like overkill for this problem. I'm sure there must be an easier way?
This is my entire error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/ValueAnimator$AnimatorUpdateListener;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
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.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\manu.joseph\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\manu.joseph\AndroidStudioProjects\WriteTrack\app\build\intermediates\dex\debug --input-list=C:\Users\manu.joseph\AndroidStudioProjects\WriteTrack\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/ValueAnimator$AnimatorUpdateListener;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
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.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Add this to your build.gradle :
configurations {
all*.exclude group: 'com.nineoldandroids'
}
Works fine for me ;)
Remove the following line and try again
compile 'com.android.support:support-v4:21.0.3'
I'm a new android developer and not long before I post this answer, I'm facing the same problem too. Googling and only 2 stackoverflow question showed up. Your question, and the stackoverflow question you provided there.
Somehow, after I remove the unused dependency library via project structures (ctrl+alt+shift+s), in my case, it is
compile 'com.rengwuxian.materialedittext:library:1.8.2'
sync the gradle and then poof! I hope it works for you too.
In the end, I ended up adding the library as an external project which did the trick for me.
Detailed instructions here..
How do I add a library project to Android Studio?
Hope this helps someone..
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.
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
}
}
If you using gson or jackson, try removing its dependencies. It worked for me.
compile 'com.google.code.gson:gson:2.1
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.