2017-03-17 100 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 
} 
相关问题