在构建调试apk时无法合并dex错误

时间:2018-02-03 03:43:12

标签: java android android-studio

当我构建调试应用程序时,我遇到了这个问题!请帮助。

错误:任务执行失败':app:transformDexArchiveWithExternalLibsDexMergerForDebug'。

  

java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex

adding "multiDexEnabled true" wont work for me

我的Gradle文件 -

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId 'com.test.thing'

        manifestPlaceholders = [onesignal_app_id               : "test",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "REMOTE"]
        minSdkVersion 15
        targetSdkVersion 26


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    repositories {
        jcenter()
        mavenCentral()  // GPUImage for Android
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/acra-4.5.0.jar')
    compile files('libs/ormlite-android-4.43.jar')
    compile files('libs/ormlite-core-4.43.jar')
    // If you want to use the GPU Filters

    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.google.firebase:firebase-ads:10.0.0'
    compile 'com.google.firebase:firebase-messaging:10.0.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'jp.wasabeef:glide-transformations:2.0.1'
    compile 'com.onesignal:OneSignal:[3.5.3,4.0.0)'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

}
apply plugin: 'com.google.gms.google-services'

`

2 个答案:

答案 0 :(得分:0)

应启用Multidex,如果必须为API< = 21

明确启用multidex

在Gradle文件中: - 像这样添加。

android {
    defaultConfig {
        multiDexEnabled true
    }
}

Depdencies部分添加以下行: -

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

在清单中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

此外,请确保您没有遗漏任何内容https://developer.android.com/studio/build/multidex.html

最后清理并构建应用

答案 1 :(得分:0)

apply plugin: 'com.android.application'



android {

compileSdkVersion 27
defaultConfig {
    applicationId "com.taggroup.www.myapp"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
dexOptions {
    javaMaxHeapSize "4g"
}
buildTypes {
    release {
        minifyEnabled false
        multiDexEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        multiDexKeepFile file('multidex-config.txt')
    }
      }
  } 
dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services-ads:11.8.0'
implementation 'com.google.firebase:firebase-ads:11.8.0'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.google.firebase:firebase-crash:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.github.bumptech.glide:glide:4.2.0'
implementation 'com.android.volley:volley:1.1.0-rc1'
implementation 'com.miguelcatalan:materialsearchview:1.4.0'
implementation 'com.paypal.sdk:paypal-android-sdk:2.15.3'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.google.firebase:firebase-core:11.8.4'
implementation 'com.github.amigold.fundapter:library:1.0'
implementation 'org.apache.httpcomponents:httpclient:4.3.5'
implementation files('./2checkout-java.jar')
}









apply plugin: 'com.google.gms.google-services'

in may case i do this and its work fine and menifast file

  <application
    android:allowBackup="true"
    android:icon="@drawable/logo_ew"
    android:label="Darzee.co"
    android:roundIcon="@drawable/logo_ew"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:replace="android:label,android:icon"
    android:name="myapp">
    <activity android:name=".Starter.Loader">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

and class to add in manifest file

package ...........;

import android.content.Context;
import android.os.Bundle;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.support.v7.app.AppCompatActivity;

import com.google.firebase.crash.FirebaseCrash;



public class myapp extends MultiDexApplication  {
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}