3

I have a library project which is using androidx dependency in it.

implementation 'androidx.appcompat:appcompat:1.0.0-rc01'

After adding library project in my app, i am getting multiple errors related to dexMerger , MultiDex , Multiple dex files define Landroid/support/v4/... .

So i searched for that file by using window+O (Navigate --> Class). Then i found that same class is used in 'androidx.appcompat:appcompat:1.0.0-rc01' and android.support.v4.. libraries . So I tried to exclude like below -

    implementation('androidx.appcompat:appcompat:1.0.0-rc01') {
         exclude module: 'support-v4'
    }

Also i have added multidex true but nothing helped. I read about AndroidX looks like it contains many classes that are similar to support libraries. What should be done in this case ? I have latest version of Android Studio and my compileSdkVersion is 28. My all dependencies are up to date. I have already added multidex dependency and my application class is also extending MultiDexApplication.

karanatwal.github.io
  • 3,613
  • 3
  • 25
  • 57

3 Answers3

1

Just setting the multidex true is not enough.

You need to include this dependency first

implementation 'com.android.support:multidex:1.0.3'

then

defaultConfig {
        ...
        multiDexEnabled true
    }

then in ur manifest

<application
        android:name="android.support.multidex.MultiDexApplication" >
        ...
</application>
Atiq
  • 14,435
  • 6
  • 54
  • 69
1

Use the Following Command to check which dependency has duplicate class

./gradlew app:dependencies

Then Exclude the module like this

{
  exclude group: 'com.android.support'
}

Hope this will solve your problem! Let me know if you have any issues!

Jagjit Singh
  • 1,909
  • 1
  • 14
  • 19
0

try

android {
    dexOptions {
        preDexLibraries = false
    }
}