使用Dagger注入依赖项时,multidex应用程序中的VerifyError [英] VerifyError in multidex app when injecting dependency with Dagger

查看:178
本文介绍了使用Dagger注入依赖项时,multidex应用程序中的VerifyError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于库的示例应用程序具有约67k个方法。它启用了multidex以克服65k方法的限制。不幸的是,启用multidex后,尝试在主要活动中注入 EndpointAdapter 时,应用程序在 VerifyError 上崩溃。

A sample app for library has ~67k methods. It has multidex enabled to overcome the 65k method limit. Unfortunately with multidex enabled the app crashes on VerifyError when trying to inject EndpointAdapter in main activity.

在保护应用程序且禁用multidex时不会发生此问题,因此它一定是由multidex和Dagger 1问题引起的。

This issue doesn't occur when the app is proguarded and the multidex is disabled, so it must be caused by multidex and Dagger 1 problems.

我确定 EndpointAdapter 在主dex文件中,但是Dagger生成的某些类位于multidex生成的第二个dex文件中。此问题在具有API< API的设备上发生。 21(例如,使用KitKat 4.4.4进行genymotion)。

I'm sure EndpointAdapter is in the main dex file, but some classes generated by Dagger are located in the second dex file generated by multidex. This issue occurs on devices with API < 21 (eg. on genymotion with KitKat 4.4.4).

是否知道为什么它会因 VerifyError 而崩溃?

Any idea why it crashes with VerifyError?

FATAL EXCEPTION: main
Process: pl.toro.libsample.debug, PID: 11775
java.lang.VerifyError: pl/toro/lib/network/EndpointAdapter
    at java.lang.Class.getDeclaredConstructors(Native Method)
    at java.lang.Class.getDeclaredConstructors(Class.java:574)
    at dagger.internal.loaders.ReflectiveAtInjectBinding.getConstructorsForType(ReflectiveAtInjectBinding.java:232)
    at dagger.internal.loaders.ReflectiveAtInjectBinding.create(ReflectiveAtInjectBinding.java:168)
    at dagger.internal.FailoverLoader.getAtInjectBinding(FailoverLoader.java:74)
    at dagger.internal.Linker.createBinding(Linker.java:224)
    at dagger.internal.Linker.linkRequested(Linker.java:141)
    at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:309)
    at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:279)
    at pl.toro.lib.app.BaseApplication.inject(BaseApplication.java:135)
    ...

此处是MultiDex标签的输出

Here's output of the MultiDex tag

VM with version 1.6.0 does not have multidex support
install
MultiDexExtractor.load(/data/app/pl.toro.libsample.debug-1.apk, false)
Detected that extraction must be performed.
Extraction is needed for file /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extracting /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes-1477675005.zip
Renaming to /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extraction success - length /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip: 187777
load found 1 secondary dex files
install done

编辑

我已切换到Dagger 2,此问题已于现在。 Dagger 2不再使用反射,这是此问题的主要因素。

I've switched to Dagger 2 and this issue is resolved as of now. Dagger 2 no longer uses reflection which is the major factor of this issue.

推荐答案

如本博客文章所指出的那样[1] ,是在安装multi-dex之后创建匕首图吗?因此,在对super的调用之后(或您自己调用 MultiDex.install() MultiDexApplication#attachBaseContext 中)。

As pointed out in this blog post[1], are you creating the dagger graph after installing the multi-dex. So in MultiDexApplication#attachBaseContext after the call to super (or calling MultiDex.install() yourself).

[1] https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part- 2

这篇关于使用Dagger注入依赖项时,multidex应用程序中的VerifyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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