'Cannot Resolve import android.support.multidex.MultiDex after change to newest Multidex

I want to use multidex in my application, At First I used depedencies : 'com.google.android:multidex:0.1', but after compile this error appeared :

Error:Execution failed for task ':packageAllDebugClassesForMultiDex'.

java.util.zip.ZipException: duplicate entry: android/support/multidex/BuildConfig.class

then I changed 'com.google.android:multidex:0.1' to 'com.android.support:multidex:1.0.1', but after that import android.support.multidex.MultiDex; in application class cannot be resolved, anybody can help ?



Solution 1:[1]

Add this into your build.gradile

 android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

defaultConfig {
    ...
    minSdkVersion 14
    targetSdkVersion 21
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
...
}

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

Also add this into your manifest

   <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.example.android.multidex.myapplication">
       <application
           ...
           android:name="android.support.multidex.MultiDexApplication">
           ...
       </application>
    </manifest>

Solution 2:[2]

You Need change

import android.support.multidex.MultiDexApplication;

to

import androidx.multidex.MultiDexApplication;

Solution 3:[3]

Add following dependency in you app gradle

 implementation 'androidx.multidex:multidex:2.0.1'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lijo Mathew
Solution 2 bad_coder
Solution 3 Dharman