【问题标题】:Android Studio "Unable to merge dex"Android Studio“无法合并dex”
【发布时间】:2018-01-10 17:22:46
【问题描述】:

我不断收到此错误。我清理了所有东西,构建、重建、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
}

【问题讨论】:

  • 已经点击了文件 => 重启和无效缓存
  • @Remario 我已经尝试过但没有成功。
  • 我认为最后一次发生的这种情况存在一些循环依赖,必须使用排除
  • @Remario 循环依赖是什么意思?它实际上是什么意思?

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


【解决方案1】:

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

android {
    defaultConfig {
       multiDexEnabled true
    }
}

【讨论】:

  • 你试过改变google-play服务库的版本吗?
【解决方案2】:

如果你重写你的应用程序类,你需要这样做

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>

希望这会对你有所帮助,在我的应用中,我有 multidex,一切正常。

【讨论】:

  • 我刚刚看到你正在使用 firebase 和 facebook,所以你需要覆盖类似这样的库 在清单中
  • 你试过了吗?
  • 我的项目中也有这个应用插件:'com.google.gms.google-services' //configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' } } } 应用 gradle 中的依赖项
猜你喜欢
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-15
  • 2018-05-04
  • 2018-04-24
相关资源
最近更新 更多