17

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 ?

Redturbo
  • 1,563
  • 8
  • 22
  • 34

3 Answers3

5

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>
  • 4
    I have already put all of that code from first, but in my application class import android.support.multidex.MultiDex; can't be resolved. – Redturbo Dec 15 '15 at 10:21
  • 2
    Still getting the `unresolved` error in my AndroidManifest.xml. – IgorGanapolsky Aug 16 '16 at 14:46
  • 2
    After following above steps, add below thing in the class which extends Application protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } – Bhavana Vadodariya Mar 22 '18 at 12:46
0

You Need change

import android.support.multidex.MultiDexApplication;

to

import androidx.multidex.MultiDexApplication;

bad_coder
  • 11,289
  • 20
  • 44
  • 72
0

Add following dependency in you app gradle

 implementation 'androidx.multidex:multidex:2.0.1'
Dharman
  • 30,962
  • 25
  • 85
  • 135
Kishan Thakkar
  • 619
  • 6
  • 11