迁移到Androidx后重复的类androidx.multidex.MultiDex

时间:2019-08-29 09:46:30

标签: android migration androidx android-multidex

我已将项目迁移到androidx。迁移后,出现以下错误。

Duplicate class androidx.multidex.MultiDex found in modules classes.jar 
(androidx.multidex:multidex:2.0.1) and jetified-android-support- 
 multidex.jar (android-support-multidex.jar)
 Duplicate class androidx.multidex.MultiDex$V14 found in modules 
 classes.jar (androidx.multidex:multidex:2.0.1) and jetified-android- 
  support-multidex.jar (android-support-multidex.jar)

如何解决这个问题?

找到了此链接,但没有答案, Duplicate class MultiDex$V14.class

添加了Gradle依赖项,

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.google.android.gms:play-services-plus:$playServiceVersion"
implementation "com.google.android.gms:play-services-auth:$playServiceVersion"
implementation "com.google.android.gms:play-services-identity:$playServiceVersion"

// Retrofit & Rx java & Dagger
implementation "com.squareup.okhttp3:logging-interceptor:$retrofitLoggerVersion"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:$rxJavaAdapterVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
implementation "com.google.dagger:dagger:$daggerVersion"

// Google services
implementation "com.google.android.gms:play-services-places:$playServiceVersion"
implementation "com.google.android.gms:play-services-location:$playServiceVersion"
implementation "com.google.android.gms:play-services-maps:$playServiceVersion"
implementation "com.google.firebase:firebase-core:$playServiceVersion"
implementation "com.google.firebase:firebase-config:$playServiceVersion"
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-appindexing:17.1.0"

// Design libraries
implementation 'androidx.appcompat:appcompat:1.0.0'

//    compile 'com.android.support:transition:26.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'


implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
annotationProcessor 'androidx.annotation:annotation:1.0.0'
implementation 'com.caverock:androidsvg:1.2.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'androidx.multidex:multidex:2.0.1'


implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'

}

3 个答案:

答案 0 :(得分:2)

问题是您已经定义了2次约束布局依赖项

实现'androidx.constraintlayout:constraintlayout:1.1.3'

答案 1 :(得分:0)

问题在于您有2个具有相同类名和包名的库。保留androidx版本并删除android支持版本。

  implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01'
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'

并在gradle属性中执行此操作

android.enableJetifier=true
org.gradle.jvmargs=-Xmx4096M -Dkotlin.daemon.jvm.options\="- 
Xmx4096M" \
-XX\:MaxPermSize\=256m -XX\:+HeapDumpOnOutOfMemoryError - 
Dfile.encoding\=UTF-8
org.gradle.daemon=true
org.gradle.configureondemand=true
android.useAndroidX=true
org.gradle.parallel=true

并添加模块应用

defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 17
    targetSdkVersion 29
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

答案 2 :(得分:0)

我通过从lib中删除jar文件来解决此问题。 Multidex jar文件位于libs文件夹中,并且它的依赖项也位于gradle中。

因此,在删除jar文件之后,它运行完美。