使用AndroidX时找不到辅助dex文件中的MultiDexApplication类 [英] MultiDexApplication class in secondary dex file not found when using AndroidX

查看:971
本文介绍了使用AndroidX时找不到辅助dex文件中的MultiDexApplication类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用'androidx.multidex:multidex:2.0.0',并且使用以下命令从清单中指向MultiDexApplication类:

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"
    ...

在build.gradle上,我还添加了以下条目:

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

defaultConfig {
    ...
    multiDexEnabled true
    ...

在低于5.0(API 21)的Android版本中运行该应用程序时,出现以下异常:

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 [...]

我使用APK浏览器,看到在classes2.dex文件中的MultiDexApplication类和其他MultiDex帮助器类.这可能就是为什么找不到类的原因.

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.

我必须强制这些类位于主classes.dex文件中吗?该如何解决?

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

推荐答案

使用 multiDexKeepFile 选项,要求MultiDexApplication最终出现在主dex文件中.

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

这篇关于使用AndroidX时找不到辅助dex文件中的MultiDexApplication类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆