MultiDexApplication class in secondary dex file not found when using AndroidX

I'm using 'androidx.multidex:multidex:2.0.0' and I'm pointing to the MultiDexApplication class from the manifest using:

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

On the build.gradle I also added the follwoing entry:

defaultConfig {
    ...
    multiDexEnabled true
    ...

When running the application in Android versions older than 5.0 (API 21) I get the following exception:

java.lang.RuntimeException: Unable to instantiate application androidx.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication" on path [...]

I used the APK browser and I saw that the MultiDexApplication class and the other MultiDex helper classes where in the classes2.dex file. That's probably why it does'nt find the class.

Must I force those classes to be on the main classes.dex file? How can this be fixed?

1 answer

  • answered 2018-11-08 08:22 Zuhrain

    Try this one. I hope it will help you.

    <application
            android:name="android.support.multidex.MultiDexApplication"
            ...