I have a trouble trying use a Google Play Services on my Android App using Android Studio.
I've tried everything and still doesn't work.
This is the error.
Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/jghg/Desktop/My App/Android/SDK/android-sdk-mac_86/build-tools/19.0.1/dx --dex --output /Users/jghg/Desktop/My App/Eureka/UDA/app/build/libs/app-debug.dex /Users/jghg/Desktop/My App/Eureka/UDA/app/build/classes/debug /Users/jghg/Desktop/My App/Eureka/UDA/app/build/dependency-cache/debug /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/classes-08979151dd1373bd3f799299d93376d22d4afa46.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/classes-167b9d3c5d689abe004c3fa5b0bcb945d3f0fc8e.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/google-play-services-ec20f8af7bb457c5095cae1afa0cee722582f198.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/support-v4-13.0.0-473d85b8d55c88bfed3404072e6c132f96543429.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/support-v4-19.0.1-861cc05365a0e9262c764da37d61e3f93dc16de6.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/support-v4-19.0.1-dcc11377c764caea791f711123b8b678f876c3b6.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-async-3.0.5-0904cb320186fb23a9a9bf25a048c5bc4ec07bc2.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-core-3.0.5-41d2d5805e2d90cf77813a126306c4cbe22583ae.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-examples-3.0.5-adc1ee9b037c8061429560e6a5fe89ce8e502db6.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-media-support-3.0.5-37d138cdc631738d13ddb6f4d34c560a9cd8e048.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-stream-3.0.5-c96c138ea216b25631a1a8b47520ecaf33f288d8.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
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)
Thanks.
Best Regards.
The error occurs when you have the same library/directory included more than once in your build.gradle's dependencies. Ok, let’s say you have an App structure that looks like this:
So you have the main “app” and then you have a bunch of sub-apps/modules/libraries. The libraries are: 1) gene_test_library, 2) genes_nine_old_androids_library, & 3) swipe_list_view_library.
My name is Gene, so that’s why there are all these “gene” libraries.
Inside the build.gradle for “app”, I have:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.0'
compile project(':libraries:gene_test_library')
//compile project(':libraries:genes_nine_old_androids_library')
compile project(':libraries:swipe_list_view_library')
}
Inside the build.gradle for gene_test_library, I have nothing:
dependencies {
}
Inside build.gradle for gene_nine_old_androids_library, I have:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
Inside build.gradle for swipe_list_view_library, I have:
dependencies {
compile 'com.nineoldandroids:library:2.4.0+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
This line of code compile fileTree(dir: 'libs', include: ['*.jar']) just means “hey, look inside the ‘libs’ folder inside this module for any jar files. I do not have anything in the libs folder of any of the modules so you can ignore that line of code.
So let’s say I uncomment out //compile project(':libraries:genes_nine_old_androids_library')
In the build.gradle for the “app” module. Then I would get the “UNEXPECTED TOP-LEVEL EXCEPTION:” error. Why is that?
Well, writing //compile project(':libraries:genes_nine_old_androids_library') inside the build.gradle for “app”, is the same as taking the build dependencies of “genes_nine_old_androids_library” module and putting it there. So uncommenting the //compile project(':libraries:genes_nine_old_androids_library') statement, the build.gradle for “app” module becomes:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.0'
compile project(':libraries:gene_test_library')
***compile fileTree(dir: 'libs', include: ['*.jar'])***
***compile 'com.android.support:appcompat-v7:21.0.0'***
compile project(':libraries:swipe_list_view_library')
}
Notice how now compile 'com.android.support:appcompat-v7:21.0.0' shows up 2x. That’s where the error is coming from.
Your google play services library is being exported from other dependencies of your project and at the compile time the dex compiler gets confused.
If you're using Gradle then including this in your project's build.gradle should exclude the support library from being exported into your main project.
apply plugin: 'android'
apply plugin: 'crashlytics'
/** Must exclude exported support jars from dependencies, or get dex duplicate class error.
* we're
**/
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.google.android.gms', module: 'play-services'
}
If you're using the andoid studio build system. Then you should go to File -> project structure and disable -> modules. Go through each module the and click on the dependency tab, uncheck the export column for for the support library and google play services library.
Post comments if you need more help.
It could also happen if you have differing versions of the same library imported in your build.gradle vs one in one of your libraries. For example, Google Play Store services requires you have them all refer to the same version I had:
app build.gradle
compile 'com.google.android.gms:play-services-base:7.5.0'
whereas:
module/library build.gradle
compile 'com.google.android.gms:play-services-cast:7.8.+'
Upgrading my app's version to 7.8.0 solved the problem
Related
I have an Ionic 3 app which gives me the following error when I'm trying to build it:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [C:\Users\zxy\Desktop\mobile_apps\newone\CourierManager\platforms\android\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\zxy\Desktop\mobile_apps\newone\CourierManager\platforms\android\app\build\intermediates\transforms\desugar\debug\8.jar(;;;;;;**.class)] (Duplicate zip entry [8.jar:ch/qos/logback/core/joran/spi/DefaultClass.class]))
My dependencies in build.gradle file looks like this:
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
compile "com.android.support:support-v4:24.1.1+"
compile "me.leolin:ShortcutBadger:1.1.17#aar"
compile "com.google.firebase:firebase-messaging:11.0.1"
compile "com.android.support:support-v4:27.+"
compile "com.squareup.okhttp3:okhttp:3.+"
compile "com.android.support:support-v4:+"
compile "com.google.firebase:firebase-dynamic-links:11.0.1"
compile "com.google.android.gms:play-services-location:11.0.1"
compile "com.android.support:support-v4:26+"
compile "com.android.support:appcompat-v7:26+"
// SUB-PROJECT DEPENDENCIES END
compile 'com.android.support:multidex:1.0.1'
}
Is there any way I can fix this without removing and adding android platform?
Found the problem and was not related to the build.gradle. I had an older version of background geolocation plugin which I updated. But it seems that it kept some dependencies to it which clashed with the new plugin. I had to manually remove it from properties.gradle.
On creating a jar for android application, i tried pulling up some external jar's in the module.but each time i try to build the jar im facing this issue.
Error:Execution failed for task ':mpos:compileJava'.
Compilation failed; see the compiler error output for details.
Error:(9, 19) error: package android.app does not exist
Error:(14, 30) error: cannot find symbol class Activity
"mpos" is my file name.
You have to put your JAR file in app/libs, and in app/build.gradle inside the dependencies section:
compile fileTree(dir: 'libs', include: ['*.jar'])
you can put your jar files in any directory you want to make inside module like app module or your library module
then you add an implementation command in build.gradle file of that module and specify the jar directories you made. like this
implementation fileTree(include: ['*.jar'], dir: 'libs')
or maybe
implementation fileTree(include: ['*.jar'], dir: 'path/to/dir')
Here is the error am getting when i try to build the app
Error:Execution failed for task ':app:processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
And these are the dependencies am using in my project
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile('com.mikepenz:materialdrawer:3.1.0#aar') {
transitive = true
}
compile 'com.github.navasmdc:MaterialDesign:1.5#aar'
compile 'com.nineoldandroids:library:2.4.+'
compile 'com.google.android.gms:play-services-ads:9.2.0'
compile 'com.google.android.gms:play-services-appindexing:9.2.0'
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
compile 'com.quinny898.library.persistentsearch:library:1.1.0-SNAPSHOT'
compile 'com.github.nirhart:parallaxscroll:1.0'
compile 'com.github.amlcurran.showcaseview:library:5.4.1'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.google.api-client:google-api-client-android:1.20.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.20.0' exclude module: 'httpclient'
compile 'com.google.apis:google-api-services-vision:v1-rev2-1.21.0'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'me.gujun.android.taggroup:library:1.4#aar'
}
After spending 2 days of searching in web i finally found a solution.
i put apply plugin: 'com.google.gms.google-services' at the end of my build.gradle file.
But i still don't understand why it didn't work when i write it on top.
May google knows :P
My goal is to distribute an .aar file that can be used by other developers in their projects. The problem I find is when i try integrate my .aar into other project, is i need specify all of the dependencies in their build.gradle file that I have already included in my .aar build.gradle.
My question it if possible only include my library as a dependency and somehow the libraries that my library depends on will get included in the other project.
For example, my library defines the following dependencies in its build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2.3.5'
compile 'commons-codec:commons-codec:1.10'
}
I wrote a test app that uses my library and add like module in Android Studio interface
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile project(':myLibrary')
}
However, this does not work. I get java.lang.VerifyErrors at runtime. What ends up working is to include this in the app's build.gradle file:
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.altbeacon:android-beacon-library:2.3.5'
compile 'commons-codec:commons-codec:1.10'
compile project(':myLibrary')
}
Why do I need to include dependencies in both the .aar and the final application? What am I not understanding about how dependencies work? Why isn't the final application able to grab the .aar's dependencies from maven or jCenter at build time?
I created a new project in Android Studio 1.1 and I built successfully. After that, I added a jar libraries and updated build.gradle file
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/google-api-client-1.18.0-rc.jar')
compile files('libs/google-api-client-android-1.18.0-rc.jar')
compile files('libs/google-api-client-appengine-1.18.0-rc.jar')
compile files('libs/google-api-client-gson-1.18.0-rc.jar')
compile files('libs/google-api-client-jackson2-1.18.0-rc.jar')
}
Now, I am getting error "Local path doesn't exist."
I search other questions about this problem but I can't solve it. Help me please!
If you added jar libraries, your Gradle file should have updated itself correctly. Local path doesn't exist means that one of the files you want to compile is not in the path you have specified.
If you used
compile fileTree(dir: 'libs', include: ['*.jar'])
Then no need to add each .jar file one by one ,it means you have to remvoe following form your build.gradle.
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/google-api-client-1.18.0-rc.jar')
compile files('libs/google-api-client-android-1.18.0-rc.jar')
compile files('libs/google-api-client-appengine-1.18.0-rc.jar')
compile files('libs/google-api-client-gson-1.18.0-rc.jar')
compile files('libs/google-api-client-jackson2-1.18.0-rc.jar')