multidex-启用了multidex的NoClassDefFoundError [英] multidex - NoClassDefFoundError with multidex enabled

查看:300
本文介绍了multidex-启用了multidex的NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用在21年之前崩溃,出现java.lang.NoClassDefFoundError app.module.SomeClass错误.

My app is crashing on pre-21 with java.lang.NoClassDefFoundError app.module.SomeClass error.

我已经启用了Multidex:

I already have Multidex enabled:

build.gradle:

build.gradle:

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
}

dependencies {
   ...
   implementation "androidx.multidex:multidex:2.0.1"
}

我的应用程序类:

class App : DaggerApplication() {
    ...
    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

在阅读了有关声明主要DEX文件中所需的类后,我创建的multidex-config.pro文件在主DEX文件中包含app.module.**:

After reading about Declaring classes required in the primary DEX file I created multidex-config.pro file to include app.module.** in primary DEX file:

-keep class app.module.** { *; }

并在build.gradle中注册它:

And registered it in build.gradle:

android {
  buildTypes {
    debug {
      ...
      multiDexKeepProguard file('multidex-config.pro')
    }
}

我通过检查build/intermediates/legacy_multidex_main_dex_list/debug/mainDexList.txt并分析调试apk(检查classes.dex是否包含app.module.SomeClass)来确认这一点.

I confirmed it by checking build/intermediates/legacy_multidex_main_dex_list/debug/mainDexList.txt and analyzing the debug apk (checking whether classes.dex includes app.module.SomeClass).

但是我仍然收到java.lang.NoClassDefFoundError app.module.SomeClass错误.

我还尝试清理缓存,在不同的机器上运行(仅在没有Android Studio的情况下为cli版本),禁用即时运行,指定javaMaxHeapSize,仅扩展MultiDexApplication等.

I also tried cleaning caches, running on different machines (cli build only without Android Studio), disabling instant run, specifying javaMaxHeapSize, just extending MultiDexApplication and etc.

接下来我可以尝试什么?

What can I try next?

推荐答案

我们在这里进行了更深入的研究:

We had a deeper look at this here:

https://issuetracker.google.com/issues/131100011

不幸的是,在21之前的设备上的某些Dalvik VM中存在一个错误,该错误中的包私有方法有时会被另一个包中的公共方法错误地覆盖.如果程序包的私有方法是最终的,则将导致以下形式的错误:

There is an unfortunate bug in some Dalvik VMs on pre-21 devices where package private methods were sometimes incorrectly overriden by public methods in another package. If the package private method is final, that will then lead to errors of the form:

E/dalvikvm: Method Lcom/mycompany/MyViewModel;.clear overrides final Landroidx/lifecycle/ViewModel;.clear

在这里看来,这可能是打击您的原因.不幸的是,针对该特定问题的唯一解决方法是将您的清除"方法重命名为其他名称,以便您不会遇到该不幸的VM错误.

It looks like that could be what is hitting you here. Unfortunately, the only workaround for that particular issue is to rename your "clear" method to something else so that you do not hit this unfortunate VM bug.

这篇关于multidex-启用了multidex的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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