hasan_shaikh
hasan_shaikh

Reputation: 1500

Duplicate class androidx.multidex.MultiDex after migrating to Androidx

I have migrated my project to androidx. After migrating I am getting the following error.

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)

How to resolve this?

Found this link but has no answer, Duplicate class MultiDex$V14.class

Gradle dependencies added belwo,

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'

}

Upvotes: 0

Views: 1147

Answers (3)

hasan_shaikh
hasan_shaikh

Reputation: 1500

I have fixed the issue by removing the jar file from libs. Multidex jar file was present in libs folder and its dependency was also there in the gradle.

So after removing the jar file, It ran perfectly.

Upvotes: 0

Kailash Chouhan
Kailash Chouhan

Reputation: 2386

The problem is that you have defined constraint layout dependency 2 times

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Upvotes: 2

raj kavadia
raj kavadia

Reputation: 1073

The problem is that u are having 2 libraries having the same class name and package name. Keep the androidx version and delete the android support version.like this

  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'

and do this in gradle properties

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

and also add in module app

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

}

Upvotes: 0

Related Questions