7

Couple of days ago, I upgraded my Android Studio, and now I am facing a problem.

Actually I am trying to build an APK file from my project to test my app on a real device and when I click at Build--> Build Apk then I receive couple of errors in Message Gradle Build. I don't know why these errors are coming please elaborate on the reason as well.

Errors

  1. Error:Error converting bytecode to dex:
    Cause: com.android.dex.DexException: Multiple dex files define Lcom/android/volley/VolleyError;

  2. Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

build.gradle file

 apply plugin: 'com.android.application'

android {
    signingConfigs {
    }

    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.dovezeal.gapp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7

    }

}



dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    //compile 'com.android.support:appcompat-v7:23.3.0'

    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:design:23.1.1'

    // Volley
    compile 'com.android.volley:volley:1.0.0'
    //compile 'com.mcxiaoke.volley:library:1.0.+'
    /* compile files('libs/com.mcxiaoke.volley library-1.0.0.jar')*/


    // RecyclerView
    compile 'com.android.support:recyclerview-v7:23.0.+'

    // A simple way to define and render UI specs on top of your Android UI.
    compile 'org.lucasr.dspec:dspec:0.1.1'

    compile files('libs/library-1.0.0.jar')

    // YouTube Player
    compile files('libs/YouTubeAndroidPlayerApi.jar')

    // GOSN
   /* compile files('libs/gson-2.2.3.jar')*/




}

Edit - 1

As janki gadhiya said in her comment below, to change minifyEnabled true and try adding multiDexEnabled true under defaultConfig
with these changes both errors above are gone, but now this following error is coming up.

  1. Error:Execution failed for task:app:transformClassesWithJarMergingForDebug' com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/android/volley/Request$Priority.class
2
  • 1
    change minifyEnabled true and try adding multiDexEnabled true under defaultConfig. May 17, 2016 at 9:55
  • @jankigadhiya Thanks for help! please check my Edit-1 section in my question as well and please explain the actual reason of these errors May 17, 2016 at 10:17

5 Answers 5

29

build.gradle file

apply plugin: 'com.android.application'

android {
signingConfigs {
}

compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.dovezeal.gapp"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/notice.txt'
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt')
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7

}

}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
//compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.1.1'

// as you already compiled gradle for volley here

compile 'com.android.volley:volley:1.0.0'

// RecyclerView
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'org.lucasr.dspec:dspec:0.1.1'

// you don't need this so comment the below line.
//compile files('libs/library-1.0.0.jar')

// YouTube Player
compile files('libs/YouTubeAndroidPlayerApi.jar')

}

Edit : Explanations

Your errors 1 - 2 : mean you are having more than 65,000 methods in your project, so I told you to set multiDexEnable true.

Your error 3 : means you're having more than one library having the implementation for the class Request$Priority.class, so the compiler is confused which to choose. So it is showing the error Duplicate entry. This will be solved by packaging options, this will let you use duplicate files.

9
  • i tried your solution for error-3 but nothing happened and the same error is coming what am i doing wrong?? May 17, 2016 at 11:16
  • Are you having volley in your libs folder ?? May 17, 2016 at 11:19
  • yes i have volley in my libs folder named as library-1.0.0 May 17, 2016 at 11:30
  • 1
    That's the problem you are compiling it as gradle dependency and adding to libs, This will duplicate the library as well as methods. Simply remove library-1.0.0.jar for libs, Then sync, clean and rebuild the project. See my edit..!! Comment or remove the compile line compile files('libs/library-1.0.0.jar') from dependencies as can be seen in my edit..!! May 17, 2016 at 11:33
  • Thanks for your help, finally it worked and i really appreciate your help. Please tell me one more thing that is it must to remove the jar file from the libs folder, isn't it enough to just comment the including statement for that lilbrary?? May 17, 2016 at 11:49
1

Add this in your build gradle

    dexOptions {
            incremental true
            javaMaxHeapSize "4g"    
}



packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
1

I am also getting the same error. When adding the compile 'com.google.firebase:firebase-ads:10.2.0' but it is removed when i do as follow:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.google.firebase:firebase-ads:10.2.0'
}

apply plugin: 'com.google.gms.google-services'**

and in BuildVarient use debugging mode.

I think it will help you.

0

while updating firebase any google play services then try to update all the libraries. this worked for me. hope it works in some cases.

-1

Bit late to answer but I faced the same issue.

I was able to rectify it using multiDexEnabled -> true and used packaging options in build.gradle, post the changes .apk got installed successfully.

Syntax:

defaultConfig {  
    ....  
    ....  
    multiDexEnabled true  
}  

packagingOptions {  
    exclude 'META-INF/DEPENDENCIES'  
    exclude 'META-INF/NOTICE'  
    exclude 'META-INF/LICENSE'  
    exclude 'META-INF/license.txt'  
    exclude 'META-INF/notice.txt'  
}  
buildTypes {  
    ...  
    ...  
}  

Hope it helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.