Vladyslav Panchenko
Vladyslav Panchenko

Reputation: 1607

Didn't find class “androidx.multidex.MultiDexApplication” on path: DexPathList on lower API <= 19 devices

I'm trying to add Multidex support to my app. But I get an error:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication" on path: DexPathList[[zip       file "/data/app/com.dfn.partner-2.apk"],nativeLibraryDirectories[/data/app-lib/se.android-2, /vendor/lib, /system/lib]]

My gradle have:

defaultConfig {
   multiDexEnabled true
}

and

depenencies {
   ...
   implementation 'androidx.multidex:multidex:2.0.1'
   ...
}

My AndroidManifest.xml have :

<application
  android:name="androidx.multidex.MultiDexApplication"
  ... >
...
</application>

What could be wrong?

Upvotes: 15

Views: 19080

Answers (6)

rsc
rsc

Reputation: 10669

In my case I had to replace in my build.gradle.kts (module: app):

implementation("com.android.support:multidex:1.0.3")

with

implementation("androidx.multidex:multidex:2.0.1")

and add the following in my gradle.properties:

android.useAndroidX=true

Upvotes: 1

itzo
itzo

Reputation: 1249

I cleaned the project:

Build -> Clean Project

and then I went to:

File -> Invalidate Caches / Restart

Compile, now should work!

Upvotes: 17

Terranology
Terranology

Reputation: 633

If you're using vector as images, change android:src to app:srcCompat in your Xml

Upvotes: 0

Isaac Sekamatte
Isaac Sekamatte

Reputation: 5598

if you are using androidx use depedency below

dependencies {
    // ...
    def multidex_version = "2.0.1"
    implementation "androidx.multidex:multidex:$multidex_version"
}

for support library use

dependencies {
    // ...
    implementation 'com.android.support:multidex:1.0.3'
}

Upvotes: 1

weston
weston

Reputation: 54781

I got this error after adding multidex until I cleaned:

./gradlew clean

Upvotes: 19

nitika
nitika

Reputation: 31

For api level < 21, platform uses Dalvik runtime for executing application code. For such cases, multidex library should be a part of the primary DEX file of your app which can then manage access to the additional DEX files and the code they contain.

In your case, looks like Multidex library is not present in the primary dex file and hence during startup, you app is giving you error: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication"

You need to explicitly specify these multidex classes in either multiDexKeepFile or multiDexKeepProguard to mark those as required in primary dex.

multiDexKeepFile

android {
    buildTypes {
        release {
            multiDexKeepFile file('multidex-main-dex-list.txt')
            ...
        }
    }
}

Content of multidex-main-dex-list.txt goes as below:

androidx.multidex.MultiDexApplication

multiDexKeepProguard

android {
    buildTypes {
        release {
            multiDexKeepProguard file('multidex-main-dex-list.pro')
            ...
        }
    }
}

Content of multidex-main-dex-list.txt goes as below:

-keep class androidx.multidex.MultiDexApplication

Upvotes: 3

Related Questions