0

Every thing was perfectly fine until I made some changes to my code and try to regenerate the signed APK. Now when I try to generate the code in android studio I get the following exception:

Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: 
com.android.ide.common.process.ProcessException: 
java.util.concurrent.ExecutionException: com.android.dex.DexException: 
Multiple dex files define Lcom/commonsware/cwac/provider/StreamStrategy;

This exception is something new to me. Here is my gradle file and dependencies

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

aaptOptions {
    noCompress 'pdf'
}
useLibrary 'org.apache.http.legacy'

defaultConfig {
    applicationId "com.user.plansmart"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 23
    versionName "1.2.6"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('D:/AndroidStudioProjects/PlanSmart/libs/itextpdf-5.4.0.jar')
compile files('D:/AndroidStudioProjects/PlanSmart/libs/cwac-provider-
0.5.2.jar')
compile files('D:/AndroidStudioProjects/PlanSmart/libs/volley.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services-ads:11.2.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.commonsware.cwac:provider:0.5.2'
compile 'com.mcxiaoke.volley:library:1.0.1'
testCompile 'junit:junit:4.12'
}

What could be the reason for error. Am not able to figure it out. Can anyone help me out.

pamo
  • 111
  • 2
  • 13

4 Answers4

0

Add this in your gradle file

configurations {
compile.exclude group: 'com.commonsware' , module:'cwac'
}
Bmbariah
  • 687
  • 2
  • 10
  • 22
0

Add multiDexEnabled true to your gradle file inside the defaultConfig block:

defaultConfig {
    applicationId "com.user.plansmart"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 23
    versionName "1.2.6"
    multiDexEnabled true
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
Sergey Emeliyanov
  • 5,158
  • 6
  • 29
  • 52
0

Add this line in your gradle file.

defaultConfig {
   applicationId "com.user.plansmart"
   minSdkVersion 15
   targetSdkVersion 25
   versionCode 23
   versionName "1.2.6"

   multiDexEnabled true 
}

hope this will Help.

Dharmishtha
  • 1,313
  • 10
  • 21
  • now i get this error Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/commonsware/cwac/provider/AssetStrategy.class – pamo Dec 18 '17 at 17:31
  • i applied two suggestions from here and my problem was resolved. By the way can you tell me why is "multiDexEnabled true" so important. – pamo Dec 18 '17 at 17:44
  • @pamo You need to use `multiDexEnabled` if only you have more than 65k methods – DeKaNszn Dec 19 '17 at 06:28
0

Remove line compile files('D:/AndroidStudioProjects/PlanSmart/libs/cwac-provider-0.5.2.jar') from dependencies in your build.gradle.

You've already defined it as compile 'com.commonsware.cwac:provider:0.5.2'

DeKaNszn
  • 2,720
  • 3
  • 26
  • 26