In Android Studio Error:Execution failed for task ':app:dexDebug' - android

Here i am work on twitter integration (login with twitter) with "Fabric Plugin" in android studio 1.1.0
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/dhruv/Dhruv/sdk/build-tools/21.0.2/dx --dex --no-optimize --output /home/dhruv/FestEvo/app/build/intermediates/dex/debug --input-list=/home/dhruv/FestEvo/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/gson/JsonSerializer;
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: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)
This is build.gradle: file
buildscript {
repositories {
// jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories{
flatDir{
dirs 'libs'
}
//jcenter()
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
applicationId "com.festevo.devtesting"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:appcompat-v7:21.0.3'
//compile 'com.spotify.sdk:spotifysdk:1.0.0-beta6#aar'
compile 'com.spotify.sdk:spotifysdk:1.0.0-beta8#aar'
// NOTE: Version must match!
// compile 'com.android.support:support-v4:+'
compile project ('libraries:FacebookSDK')
compile project ('libraries:simple-crop-image-lib')
compile project ('libraries:SlidingMenu')
compile project ('libraries:nineoldandroids')
compile project ('libraries:google-play-services_lib')
compile('com.twitter.sdk.android:twitter:1.3.2#aar') {
transitive = true;
}
}
Please suggest me how to solve my problem thanks you in advance:)

Had this error as well. The key is here: "Multiple dex files define Lcom/google/gson/JsonSerializer;"
Most likely you are referencing more than one version of gson in your app. So you can right click on your Project Module -> Open Module Settings -> Dependencies tab and any remove any extra gson versions.
If you want a clearer picture, you can go into terminal in Android Studio and do grep -r gson to see all references.

Related

:app:compileDebugJavaWithJavac error: error reading C:\... \.android\build-cache\167256a7a343274ac6d230f06a5526cf83b55ac4\output\jars

Good day friends,
The error
:app:compileDebugJavaWithJavac error: error reading C:\ .... \.android\build-cache\167256a7a343274ac6d230f06a5526cf83b55ac4\output\jars\classes.jar; error in opening zip file and also the same but ending in cannot read zip file
occurs when running the application. After that, I get all sorts of errors obviously such as package android.support.v7.app does not exist etc.
I have tried cleaning, rebuilding, cleaning the .android\build-cache etc, etc, and nothing. I have also looked at the other answers provided here, but none of them fixed this issue.
I am running jdk1.8.0_40 as JDK
This is my top gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and my app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "es.sample.android.myoffice"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
repositories {
mavenLocal()
flatDir {
dirs 'libs'
}
}
apply plugin: 'android-apt'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:palette-v7:25.3.1'
compile 'com.google.firebase:firebase-config:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'com.google.android.gms:play-services-appinvite:10.0.1'
compile 'com.firebase:firebase-jobdispatcher:0.5.2'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
}
apply plugin: 'com.google.gms.google-services'
Thanks!
NEW EDIT
Apparently is only affecting to:
Error:(18, 30) error: package android.support.v7.app does not exist
After going crazy and trying everything that I could, I came up with a solution.
I had go back to Android Support Library version 45. For some strange reason, version 46 was causing all this mess for android.support.v7.app
So do the following:
Download the version here and unzip it to a local place in your computer
Go to your m2repository in your SDK root folder .. /extras/android and delete it
Cut previously unzipped m2repository folder and paste it to previous location
Clean and run your app

Not able to add gms and FCM dependencies

I'm new to android. I'm building an App that requires Map as well as FCM. So to customize markers and set latitude and langitude I'm using gms.
This is my app level gradle build file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
and the below is my project level gradle build file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
So when I include both the following dependencies in app level gradle file.
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
I'm getting the following error while running the application.
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/internal/zzab;
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.7.0_79\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 20.671 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
But when I remove the firebase-messaging dependency it's working. Please help. Thanks in advance
In your gradle use same version of Gms and firebase dependencies.
And as you are only using Google map , no need to import the whole library, use only the map selective portion.
com.google.firebase:firebase-messaging:10.2.1
com.google.android.gms:play-services-maps:10.2.1
in your code:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
com.google.firebase:firebase-messaging:10.2.1
com.google.android.gms:play-services-maps:10.2.1
}

Failed to complete gradle execution. Cause is empty. 65K Methods Limit

This is de build.gradle of app module:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 10
targetSdkVersion 22
versionCode 19
versionName "1.6.2"
}
buildTypes {
release {
minifyEnabled false
debuggable false;
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
repositories {
maven { url 'http://dl.bintray.com/madcyph3r/maven/' }
maven { url 'http://dl.bintray.com/amulyakhare/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.google.android.gms:play-services:7.5.0"
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'net.glxn.qrgen:android:2.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'de.madcyph3r:materialDrawer:1.1.1#aar'
compile 'com.google.maps.android:android-maps-utils:0.3.4'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.google.zxing:core:3.2.0'
compile 'me.dm7.barcodescanner:zxing:1.7'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'org.apache.commons:commons-io:1.3.2'
compile files('libs/GraphView-4.0.1.jar')
compile files('libs/mpandroidchartlibrary-2-1-0.jar')
compile files('libs/bitcoinj-core-0.12.3-bundled.jar')
}
And this is build.gradle of project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.google.gms:google-services:1.3.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I'm trying use Google cloud Messaging , I have followed all steps in https://developers.google.com/cloud-messaging/android/client but when I synchronize gradle files with the project I get this:
Failed to complete gradle execution. Cause: [empty]
I tried implement this solution: Android Studio: failed to complete gradle execution, cause is empty and other similar solutions but result is same.
What could be the solution to this problem? Someone has happened this?
Thaanks in advance!!
I found the solution:
The problem lies not in GCM. The problem arises when I try to compile the app. I used the command;
gradlew assembleDebug --stacktrace
and I threw this error:
Unable to execute dex : method ID not in [0 , 0xFFFF ] : 65536.
I've solved with the steps described Google here:
Building Apps with Over 65K Methods

Multiple dex files define android/support/annotation/AnimRes

When I`m tring to run my app, I receive the following error:
app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug
:app:dexDebug
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 (x86)\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 2
The content of the gradle script is:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
minSdkVersion 10
targetSdkVersion 22
versionCode 289
versionName "2.2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles 'proguard-android.txt', 'proguard-rules.txt'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile('com.facebook.android:facebook-android-sdk:3.23.1') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile('com.crashlytics.sdk.android:crashlytics:2.3.1#aar') {
transitive = true;
}
compile project(':UtilsLibrary')
compile project(':NumberPickerLibrary')
compile project(':drag-sort-listview-lib')
compile project(':GoogleAPI Library')
compile project(':MenuDrawerLibrary')
compile project(':IOLibrary')
compile project(':AR Library')
compile project(':GoogleLicense')
compile project(':android-maps-utils-library')
}
I`m sure that somehow I added twice an of the google libraries.
Thanks.
check the other modules, which are compiled for this module.
The best way to see what is contained as dependencies is to use gradlew.
see here how to generate the dependencie three.
now you have to look with the three where the other google librarie is.

Android and Jenkings build, using Gradle

I'm having an annoying problem trying to integrate Android gradle with Jenkins Android Emulator Plugin.
I set those properties to my Android Emulator:
Android OS version: android-18
Screen density: 160
Screen resolution: HVGA
Device locale: es_ES
Target ABI: armeabi-v7a
Emulator name suffix: android18
When I start the process, the emulator starts propertly, but I get the following error:
[Gradle] - Launching build.
[workspace] $ /var/lib/jenkins/jobs/properati-android/workspace/gradlew clean assemble
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.android.support:support-v4:20.0.0.
     Required by:
         workspace:app:unspecified
In Gradle plugin settings (on Jenkins as a command line Task) I'm using gradlew clean assemble command to build
The following are the build.gradle files I'm currently using in my project.
1) Main gradle file
projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
2) Project Gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.app"
minSdkVersion 9
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.googlecode.android-query:android-query:0.25.9'
compile 'com.github.castorflex.smoothprogressbar:library:0.5.2'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.newrelic.agent.android:agent-gradle-plugin:3.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'android'
apply plugin: 'newrelic'
dependencies {
compile 'com.newrelic.agent.android:android-agent:3.+'
}
I would appreciate any help or tip you could share. Thanks in advance!
UPDATE & Solution:
I solved this issue by adding AndroidSupportV4.jar to my libs folder and changing my build.gradle file to the following:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:support-v4:20.0.0' --OLD LINE
compile files ("libs/AndroidSupportV4.jar") --NEW LINE
compile 'com.googlecode.android-query:android-query:0.25.9'
compile 'com.github.castorflex.smoothprogressbar:library:0.5.2'
}

Categories

Resources