2017-03-17 87 views
1

當我在nexus 5設備上構建並運行項目時,它運行良好。但是,當我建立和我的三星GT-I9100(API 16)運行該項目,它顯示的錯誤:apache錯誤:任務':app:transformClassesWithJarMergingForDebug'的執行失敗。 > com.android.build.api

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.dex.DexException: Multiple dex files define Lorg/apache/http/Consts;

然後我添加multiDexEnabled true我gradle這個。當我嘗試再次編譯時,現在我收到以下錯誤消息 錯誤:執行任務':app:transformClassesWithDexForDebug'失敗。

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/http/Consts;

,但再次,它工作正常,當我編譯它在我的Nexus 5(API 23)

我的應用程序gradle這個文件

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 
    defaultConfig { 
     applicationId "com.project.example" 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 

    } 
    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
    } 
} 

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.android.support:multidex:1.0.1' 
    compile 'com.mcxiaoke.volley:library-aar:1.0.0' 
    compile 'org.apache.httpcomponents:httpcore:4.4.1' 
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1' 
    compile 'com.google.firebase:firebase-messaging:10.0.1' 
    compile 'com.android.support:design:25.1.1' 
    compile 'com.google.firebase:firebase-core:10.2.0' 
    compile 'com.google.firebase:firebase-database:10.2.0' 
    compile 'com.android.support:appcompat-v7:25.2.0' 
    testCompile 'junit:junit:4.12' 
} 
+0

發表您的品位文件 – Umarov

+0

@Umarov的核實。我編輯了他們 – VincentTheonardo

回答

0

你必須在你的gradle這個新增的依賴作爲以及

compile 'com.android.support:multidex:1.0.1' 

只增加multiDexEnabled true是行不通的,因爲你的minSkdVersion低則21見DOCUME ntation這裏Conifigure you apps for multidex

你也需要在你的應用類擴展MultiDexApllication代替Application

+0

我已經完成了你所說的所有事情,但問題仍然存在 – VincentTheonardo

+1

@VincentTheonardo請更新你在這裏的問題。其他人可能不會在這裏閱讀此評論。 – Prashant

0

嘗試增加以下在建的gradle級代碼(的build.gradle)

dexOptions { 
javaMaxHeapSize "4g" 
preDexLibraries = false 
} 
相關問題