Android Studio“无法合并dex”

时间:2018-01-10 17:22:46

标签: android gradle android-gradle build.gradle multidex

我一直收到这个错误。我清理了所有东西,构建,重建,jumbomode,MultidexApplication我尽可能地尝试了一切,但一切都没有成功。

有时需要逐个删除依赖项,但现在它没用了。

这个错误超过一周我就遇到了这个错误。有谁知道如何解决它?

下面是我的配置文件。

app.gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven {
        url 'https://maven.fabric.io/public'
    }
}

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId ""
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 6
        versionName "1.0.5"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        /*manifestPlaceholders = [ onesignal_app_id: "",
                                 onesignal_google_project_number: "REMOTE" ]*/

        manifestPlaceholders = [
                manifestApplicationId          : "${applicationId}",
                onesignal_app_id               : "",
                onesignal_google_project_number: ""
        ]
    }
    dexOptions {
//        jumboMode true
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            ext.enableCrashlytics = false
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    //noinspection GradleCompatible
    implementation 'com.android.support:design:26.1.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:support-v4:26.1.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
//    implementation 'com.android.support:customtabs:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    // one signal
    implementation 'com.onesignal:OneSignal:3.7.1@aar'
    // zendesk
    implementation 'com.zendesk:sdk:1.10.0.1'
    implementation('com.zendesk:sdk:1.10.0.1@aar') {
        transitive = true
    }
    // UnifyID
    implementation 'id.unify.sdk:sdk:0.8.1'
    implementation 'com.android.support:multidex:1.0.2'
    // circle ImageView
    implementation 'de.hdodenhof:circleimageview:2.1.0'
    // fabric
    implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true
    }
    // fitChart
    implementation 'com.txusballesteros:FitChart:1.0'
    // retrofit2
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    // google play services(google fit, google map, location)
    //noinspection GradleCompatible,UseOfBundledGooglePlayServices
//    implementation 'com.google.android.gms:play-services:11.8.0'
    //noinspection GradleCompatible
    implementation 'com.google.android.gms:play-services-fitness:11.8.0'
    implementation 'com.google.android.gms:play-services-maps:11.8.0'
//    implementation 'com.google.android.gms:play-services-location:11.8.0'
//    implementation 'com.google.android.gms:play-services-places:11.8.0'
    // firebase
    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    // facebook
    implementation 'com.facebook.android:facebook-android-sdk:4.25.0'
    implementation 'com.twitter.sdk.android:twitter:3.1.1'
    // glide
    implementation 'com.github.bumptech.glide:glide:4.5.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
}

project.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

//apply plugin: 'com.jfrog.artifactory'
//apply plugin: 'maven-publish'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://maven.google.com" }
        //maven { url "https://artifacts.unify.id" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.0'
        classpath 'io.fabric.tools:gradle:1.25.1'

        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
//        classpath 'io.fabric.tools:gradle:1.22.1'
        //classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            url "http://gradle.unify.id/artifactory/gradle-release"
            credentials {
                username = ""
                password = ""
            }
        }
        maven { url 'https://zendesk.jfrog.io/zendesk/repo' }
        maven { url "https://maven.google.com" }

        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2 个答案:

答案 0 :(得分:-1)

尝试使用gms:play-services:X.X.X库的不同版本组合,并尝试在应用模块 build.gradle文件中添加此代码

android {
    defaultConfig {
       multiDexEnabled true
    }
}

答案 1 :(得分:-1)

如果你覆盖你的Application类,你需要这样做

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

如果您的应用程序标记中的清单文件中的情况不是您应该添加此

 <application
        android:name="android.support.multidex.MultiDexApplication" >
    ...
</application>

希望这会对你有所帮助,在我的应用程序中我有多索引,一切正常。