I'm trying to build an app with Google Maps but whenever I try to run it there's an error message. I've added the following code to my build.gradle:
dependencies {
compile 'com.google.android.gms:play-services:4.2.42'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And here's the error message:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Fredrik\AppData\Local\Android\android-studio\sdk\build-tools\19.0.3\dx.bat --dex --output
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\dex\debug
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\classes\debug
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\dependency-cache\debug
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\pre-dexed\debug\android-support-v4-0245b39e700edf6a0cb399c720bb8d324f78e6d1.jar
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\pre-dexed\debug\classes-05dd9eee723585a17563ec87ce727a6f7bafa3c6.jar
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\pre-dexed\debug\support-v4-19.0.1-b477505a5fac609297d4a580b1fdd1110916d42b.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
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)
When I delete the code in build.gradle it runs fine, but then Maps won't work of course ;). This isn't just the case with Play Services but it does the same thing when I try to add the Support Library.
Does anyone know something that could help me solve the problem?
When using Gradle, don't include android-support-v4 by including the jar file directly; if you do it this way, the build system isn't able to disambiguate multiple copies of the support library it may encounter through direct or transitive dependencies, and you get exactly this error. Instead, remove the jar from your libs directory and include it by supplying its Maven coordinate in the dependencies block of your build file:
dependencies {
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.android.support:support-v4:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Related
I am getting an error in Android Studio for my application which is as follows:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
Error:Execution failed for task ':app:transformClassesWithDexForInmemoryDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
Dependencies included are :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile ('junit:junit:4.12')
compile ('com.android.support:appcompat-v7:23.2.1')
compile ('com.soundcloud.android:android-crop:0.9.10#aar')
compile ('com.squareup:otto:1.3.6')
compile ('com.squareup.picasso:picasso:2.5.2')
compile ('com.android.support:recyclerview-v7:+')
compile ('com.android.support:cardview-v7:+')
}
I have tried tried setting multidex to true but it still doesn't solve the problem. I have also tried excluding support-v4 in dependencies.
Please help me resolve the error.
write this on your build.gradle "compile 'com.android.support:multidex:1.0.1' in dependency
Then Open your application class and inside attachBaseContext method
write MultiDex.install(this);
Hope it would help you
I am having the following dependencies in the build.gradle file. Note that I am using Ionic/Cordova mobile app.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile project(path: "CordovaLib", configuration: "debug")
releaseCompile project(path: "CordovaLib", configuration: "release")
compile "com.google.android.gms:play-services-analytics:+"
compile "com.onesignal:OneSignal:3.3.0#aar"
compile "com.google.android.gms:play-services-gcm:+"
compile "com.google.android.gms:play-services-location:+"
compile "com.google.android.gms:play-services-ads:8.4+"
// SUB-PROJECT DEPENDENCIES END
}
I get the below error during the build process.
Error: cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzah;
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzah;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:591)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:546)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:528)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
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)
FAILURE: Build failed with an exception.
I read the below SO links. It says about app level and module level gradle files. I am not sure which 2 files are those.
Version conflict updating to 8.4.0
Multiple dex files define Lcom/google/android/gms/internal/zzim;
Multiple dex files define Lcom/google/android/gms/internal/zzau
That error occurs when you have the same library/directory included more than once in your build.gradle's dependencies. This looks also to be conflict with another plugin your using as stated in this thread.
You can check these links:
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define
Check all your dependencies in your build.gradle file. Are you referencing a dependency that also includes a dependency you have already included? For example, if your including appcompat-v7 there is no need to include appcompat-v4 since v7 includes all features from v4.
DexException: Multiple dex files
This error is caused by having too many method referenced in your project. You can read more here. Generally it means that you need to remove unused libraries or use proguard even on debug build to reduce the number of method referenced. You may also go with the multi-dex approached mentioned in the article but it makes your project more complicated.
I am not sure about the reason, but adding Google Admob library plugin the build was successful.
NOTE: I am using cordova plugin for Admob.
I have imported a project in Android Studio. I am attempting to run the code but the app fails with the following errors, not sure what the problem is.
These are the libraries i am using.
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile files('libs/android-async-http-1.4.6.jar')
compile files('libs/android-query-full.0.26.8.jar')
compile files('libs/android-viewbadger.jar')
compile files('libs/Android-WebRequest.jar')
compile files('libs/AndroidSwipeLayout-v1.1.6.jar')
compile files('libs/google-api-client-1.20.0.jar')
compile files('libs/google-api-services-bigquery-v2-rev200-1.20.0.jar')
compile files('libs/google-http-client-1.20.0.jar')
compile files('libs/google-http-client-jackson2-1.20.0.jar')
compile files('libs/google-oauth-client-1.20.0.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/Parse-1.9.2.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile files('libs/com-crashlytics-sdk-android_answers-classes.jar')
compile files('libs/com-crashlytics-sdk-android_beta-classes.jar')
compile files('libs/com-crashlytics-sdk-android_crashlytics-classes.jar')
compile files('libs/io-fabric-sdk-android_fabric-classes.jar')
and error i am getting is
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\ch-e01062\AppData\Local\Android\android-sdk\build-tools\23.0.0-preview\dx.bat --dex --no-optimize --output C:\Users\ch-e01062\Downloads\FreeB2\app\build\intermediates\dex\debug --input-list=C:\Users\ch-e01062\Downloads\FreeB2\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/google/android/gms/analytics/internal/Command$1;
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)
i have tried many available solutions but nothing is working.Any help will be appreciated.
After hours with the same problem i found the answer.
The problem is that you have multiple libs with the same classes inside, so the solution would be to either remove the repeating files from one of the libs.
You have to:
Open the lib libGoogleAnalyticsServices.jar with WinRAR, 7Zip or whatever.
Go to com/google/android/gms/analytics/internal and delete the files Command$1.class and Command.class.
In your case you may have to remove other repeating files, not sure because you have many files. Either way, you can also force it to ignore some of those files IF the method above didn't work. Put the following code inside the Android block on your build.gradle file:
defaultConfig {
multiDexEnabled true
}
dexOptions {
preDexLibraries = false
}
I'm facing a problem with adding the itextg-5.5.4.jar to my Android project in Android Studio. I copied the jar file to my libs folder and added it as a library.
I can use the classes in my project but when i try to start the app on my device, a UNEXPECTED TOP-LEVEL EXCEPTION occurs.
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/Paule/Documents/Android SDK/sdk/build-tools/android-4.4W/dx --dex --output
Error Code:
2
Output:
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)
build.gradle contains the dependencies (there are 14 more jar dependencies, I've removed them for a better overview)
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.0'
compile 'com.google.android.gms:play-services-base:6.5.87'
compile files('src/main/libs/itextg-5.5.4.jar')
....
....
}
Does anyone know how to fix that error?
Receiving this exception whilst trying to build my project. Have searched around for an answer but most cases seem to be different to mine.
Other solutions include clearing temporary files or doing a gradle clean. This does temporarily solve the issue but it reappears again after a few builds. Another way this issue can occur is if the project contains multiple copies of a library. I have searched through my project and only have one instance of activation.jar which is in my libs directory. Most other solutions seem to involve changing the build path in Eclipse, but my problem is occurring on Android Studio 0.5.8. I am using Java 1.7.
Gradle Console
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException:
Multiple dex files define
Lcom/sun/activation/registries/LineTokenizer;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
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)
Libraries in libs dir:
activation.jar
additionnal.jar
androidplot-core-0.5.1.jar
annotations.jar
DatawindAdsSdk-2.0.jar
jpct_ae.jar
jsr305-1.3.9.jar
libGoogleAnalyticsV2.jar
mail.jar
twitter4j-core-3.0.5.jar
Dependencies: Note - ":android-cropimage" does not have any dependencies in build.gradle
Main module:
dependencies {
//Library Projects
compile project(':android-cropimage')
compile project(':facebook')
//Android SDK Libraries
//This library requires "Google Play Services" and "Google Repository" to be downloaded via SDK Manager.
compile 'com.google.android.gms:play-services:4.4.52'
//Third Party
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.j256.ormlite:ormlite-core:4.46'
compile 'com.j256.ormlite:ormlite-android:4.46'
compile 'net.hockeyapp.android:HockeySDK:3.0.1'
compile 'org.apache.httpcomponents:httpmime:4.2.5'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.squareup.picasso:picasso:2.2.0'
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'org.msgpack:msgpack:0.6.11'
}
Facebook module:
dependencies {
compile 'com.android.support:support-v4:19.1.0'
}
Turns out this is due to a bug with the Android Gradle plugin's incremental dex option on version 0.10.2 (https://groups.google.com/forum/#!topic/adt-dev/6KbhReCE_fo). Removing the following from my build.gradle file solved the issue:
android {
dexOptions {
incremental true
}
}
As #Marepork anwered there is a bug withing gradle that has not been fixed
If you still want to use incremental build you can always use build variants and fordebug use multidex and for release a proguard