导入模块时无法合并dex

问题描述 投票:1回答:3

我知道有很多问题,但我尝试了大多数的解决方案,但都没有。我有一个应用程序,我已导入模块。当我尝试运行应用程序时,我无法合并dex异常。

build.gradle(app模块)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.meditab.imspatient"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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.constraint:constraint-layout:1.0.2' // Constraint layout
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // Kotlin

// Support libraries
implementation "com.android.support:appcompat-v7:$appcompat_version"
implementation "com.android.support:support-v4:$appcompat_version"

compile project(path: ':commonutils')
 }

build.gradle(导入模块)

 apply plugin: 'com.android.library'

android {
compileSdkVersion 27
buildToolsVersion '27.0.2'

defaultConfig {
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
}
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'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.jakewharton:butterknife:8.8.1'

// Support libraries
compile "com.android.support:appcompat-v7:$appcompat_version"
compile "com.android.support:design:$appcompat_version"

// Rx related libraries
compile 'io.reactivex:rxjava:1.1.1'
compile 'io.reactivex:rxandroid:1.1.0'
//compile 'com.netflix.rxjava:rxjava-core:0.+'
// Networking related libraries
compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-jackson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'

compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-base:11.8.0'
compile 'com.google.android.gms:play-services-location:11.8.0'
compile 'com.estimote:sdk:0.10.+@aar'
}

build.gradle(项目级别)

buildscript {
ext.kotlin_version = '1.2.21'
ext.appcompat_version = '27.0.2'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    // Needed for the common utils module
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

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

我尝试删除.gradle文件夹,清理项目并重建它。什么都行不通。我还尝试在导入模块的build.gradle中使用实现而不是编译。任何帮助将不胜感激。提前致谢。

android android-gradle kotlin kotlin-android-extensions
3个回答
0
投票

似乎您声明依赖的2个库导致重复条目。

问题是您不能拥有由2个不同库声明的完全相同的类或注释。如果它们是同一个库的不同版本,则可能会挑选具有最高版本的库,但如果它们是完全不同的库,则无法确定dex文件中应包含哪个实现。

第一个是:

'com.netflix.rxjava:rxjava-core:0.+'

你为什么要用这个?你已经定义了一个对RxJava('io.reactivex:rxjava:1.1.1')的依赖,它们可能有许多共同的类,我想到的第一个和我检查的是rx.Observable。该回购的最新更新是2014年11月,超过3年前。除了冲突之外,仅这一事实应该是不使用它的一个很好的理由。

第二个问题是:

'org.jetbrains:annotations-java5:15.0'

我想你正在导入这个以获得org.jetbrains.annotations.Nullable,这已经在你的项目中可用了,因为Kotlin stdlib对org.jetbrains:annotations有一个依赖,它也声明了它。因此冲突。

删除这两个依赖项,你很可能实际上并不需要它们,并且项目编译。


0
投票

我不是百分百肯定,但我认为你需要在你的应用程序中启用multidex。检查此链接:Enable Multidex

只是想帮忙。


0
投票

在我以前的项目中有多个模块如果我启用Proguard我遇到了同样的错误。这个错误令人沮丧,在我的情况下,我在检查项目依赖图后解决了问题(Using gradle to find dependency tree可能会帮助你找到依赖项)播放服务的不同版本在我的情况下造成

© www.soinside.com 2019 - 2024. All rights reserved.