Error creating APK file in Android Studio 2.1.1

A few days ago, I updated my Android studio and now I have a problem.

Actually, I am trying to create an APK file from my project in order to test my application on a real device, and when I click Build → Build Apk , I get a couple of errors in the Message Gradle Build. I do not know why these errors go, please explain in detail the reason.

Mistakes

  • Error: bytecode to dex conversion error:
    Reason: com.android.dex.DexException: multiple dex files define Lcom / android / volley / VolleyError;

  • Error: execution completed 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 '' terminated with nonzero 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')*/ } 

Change - 1

As janki gadhiya said in his comment below, change minifyEnabled true and try adding multiDexEnabled true to defaultConfig
with these changes, both of the above errors disappeared, but now this next error occurs.

  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
+7
android build.gradle apk
source share
5 answers

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 mistakes 1 - 2 : means that you have more than 65,000 methods in your project, so I told you to set multiDexEnable true .

Your error 3 : means that you have more than one library that has an implementation for the Request$Priority.class class, so the compiler gets confused to choose. Therefore, a duplicate entry error is displayed. This will be allowed by packaging options , this will allow you to use duplicate files.

+28
source share

Add this to your gradle assembly

  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
source share

I also get the same error. When adding compile 'com.google.firebase: firebase-ads: 10.2.0' but it is deleted when I do the following:

 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'** 

BuildVarient uses debug mode .

I think this will help you.

+1
source share

when updating firebase of any Google Play services, and then try updating all libraries. it worked for me. hope it works in some cases.

0
source share

A little late to answer, but I ran into the same problem.

I managed to fix it using multiDexEnabled true and use the packaging options in build.gradle, after the changes .apk was successfully installed.

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 this helps.

-one
source share

All Articles