简体   繁体   中英

Use Dagger2 on Android run into VerifyError on certain devices

I have an Android application that uses Dagger2. I have a Dagger Component called AppComponent , an Activity called MainActivity . MainActivity has a injected field: @Inject MainDataModel mModel , and uses DaggerAppComponent.inject(mainActivity) to satisfy the field. I put the Component init code in Application.onCreate(). During runtime, I run into VerifyError during Component initialization.

Fatal Exception: java.lang.VerifyError: com/myapp/a
   at com.myapp.dagger.DaggerAppComponent.initialize(DaggerAppComponent.java:39)
   at com.myapp.dagger.DaggerAppComponent.(DaggerAppComponent.java:29)
   at com.myapp.dagger.DaggerAppComponent.(DaggerAppComponent.java:19)
   at com.myapp.dagger.DaggerAppComponent$Builder.build(DaggerAppComponent.java:75)
   at com.myapp.dagger.ComponentHolder.init(ComponentHolder.java:15)
   at com.myapp.AppInitializer.init(AppInitializer.java:13)
   at com.myapp.app.MyApp.onCreate(MyApp.java:341)
   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1069)
   at com.lbe.security.service.core.client.b.x.callApplicationOnCreate(Unknown Source)
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4699)
   at android.app.ActivityThread.access$1300(ActivityThread.java:171)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1447)
   at android.os.Handler.dispatchMessage(Handler.java:107)
   at android.os.Looper.loop(Looper.java:194)
   at android.app.ActivityThread.main(ActivityThread.java:5433)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:525)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
   at dalvik.system.NativeStart.main(NativeStart.java)

After checking with the mapping file, I found out that the class causing the VerifyError msg is a MainActivity_MembersInjector , which is also generated by Dagger.

The line that causes this is this.mainActivityMembersInjector = MainActivity_MembersInjector_MembersInjector.create(MembersInjectors.noOp(), this.mainDataModelProvider); inside class DaggerAppComponent .

One thing to not is that it only happens on certain devices though, like Xiaomi 2014011. Any idea how to fix that?

你有multiDex启用到您build.gradle配置?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM