当我在android studio中生成签名的APK时,我得到了DexException
直到我对代码进行了一些更改并尝试重新生成签名的APK之前,所有事情都很好。现在,当我尝试在android studio中生成代码时,我得到以下例外:当我在android studio中生成签名的APK时,我得到了DexException
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;
这个例外对我而言是新鲜事。这是我的gradle文件和依赖关系
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'
}
错误的原因是什么?我无法弄清楚。谁能帮我吗。
从build.gradle中的依赖关系中删除行compile files('D:/AndroidStudioProjects/PlanSmart/libs/cwac-provider-0.5.2.jar')
。
您已将其定义为compile 'com.commonsware.cwac:provider:0.5.2'
在gradle这个文件中添加此
configurations {
compile.exclude group: 'com.commonsware' , module:'cwac'
}
添加multiDexEnabled true
到defaultConfig块内的gradle的文件:
defaultConfig {
applicationId "com.user.plansmart"
minSdkVersion 15
targetSdkVersion 25
versionCode 23
versionName "1.2.6"
multiDexEnabled true
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
在gradle
文件中添加此行。
defaultConfig {
applicationId "com.user.plansmart"
minSdkVersion 15
targetSdkVersion 25
versionCode 23
versionName "1.2.6"
multiDexEnabled true
}
希望这会有所帮助。
现在我得到这个错误错误:任务':app:transformClassesWithJarMergingForRelease'的执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复项:com/commonsware/cwac/provider/AssetStrategy.class – pamo
我从这里应用了两个建议,我的问题已解决。顺便说一下,你能告诉我为什么“multiDexEnabled true”如此重要。 – pamo
@pamo如果你只有65k以上的方法,你需要使用'multiDexEnabled' – DeKaNszn
请检查此链接并启用multidex。 https://stackoverflow.com/questions/26609734/how-to-enable-multidexing-with-the-new-android-multidex-support-library – RejoylinLokeshwaran
添加此行multiDexEnabled true在您的gradle。 –