MultiDexApplication class in secondary dex file not found when using AndroidX

*爱你&永不变心* 提交于 2019-12-21 05:25:13

问题


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:


I had the same issue after migrating to AndroidX, though the application class in question was our custom Application class. I tried to clean the project from Android Studio but that didn't work, so eventually I manually removed all the build folders and for good measure did "Invalidate caches and restart" for Android studio as well and that seems to have done the trick for me at least.




回答2:


Use the multiDexKeepFile option to require that MultiDexApplication ends up in the main dex file.



来源:https://stackoverflow.com/questions/53203590/multidexapplication-class-in-secondary-dex-file-not-found-when-using-androidx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!