2017-12-18 164 views
0

直到我對代碼進行了一些更改並嘗試重新生成簽名的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' 
} 

錯誤的原因是什麼?我無法弄清楚。誰能幫我嗎。

+0

請檢查此鏈接並啓用multidex。 https://stackoverflow.com/questions/26609734/how-to-enable-multidexing-with-the-new-android-multidex-support-library – RejoylinLokeshwaran

+0

添加此行multiDexEnabled true在您的gradle。 –

回答

0

從build.gradle中的依賴關係中刪除行compile files('D:/AndroidStudioProjects/PlanSmart/libs/cwac-provider-0.5.2.jar')

您已將其定義爲compile 'com.commonsware.cwac:provider:0.5.2'

0

在gradle這個文件中添加此

configurations { 
compile.exclude group: 'com.commonsware' , module:'cwac' 
} 
0

添加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" 
} 
0

gradle文件中添加此行。

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

    multiDexEnabled true 
} 

希望這會有所幫助。

+0

現在我得到這個錯誤錯誤:任務':app:transformClassesWithJarMergingForRelease'的執行失敗。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重複項:com/commonsware/cwac/provider/AssetStrategy.class – pamo

+0

我從這裏應用了兩個建議,我的問題已解決。順便說一下,你能告訴我爲什麼「multiDexEnabled true」如此重要。 – pamo

+0

@pamo如果你只有65k以上的方法,你需要使用'multiDexEnabled' – DeKaNszn

相關問題