dagger2在ContentProvider中注入数据库错误NoClassDefFoundError - DbOpenHelper_Factory.get

时间:2018-05-12 15:33:26

标签: android dependency-injection dagger-2 greendao butterknife

我正在尝试设置Android MVPApp&在我的项目中成功设置了Dagger 2,butterknife。它正在处理我的设备上的所有活动,但仍然是Android的firebase crashlytics仍然显示几个用户使用Android 19&以下版本受此问题影响。这是来自firebase控制台的堆栈跟踪 -

com.urtutors.eduwiser.data.db.DbOpenHelper_Factory.get (DbOpenHelper_Factory.java:35)
com.urtutors.eduwiser.data.db.DbOpenHelper_Factory.get (DbOpenHelper_Factory.java:10)
dagger.internal.DoubleCheck.get (DoubleCheck.java:47)
com.urtutors.eduwiser.data.db.AppDbHelper_Factory.get (AppDbHelper_Factory.java:21)
com.urtutors.eduwiser.data.db.AppDbHelper_Factory.get (AppDbHelper_Factory.java:7)
dagger.internal.DoubleCheck.get (DoubleCheck.java:47)
com.urtutors.eduwiser.di.module.ApplicationModule_ProvideDbHelperFactory.get (ApplicationModule_ProvideDbHelperFactory.java:30)
com.urtutors.eduwiser.di.module.ApplicationModule_ProvideDbHelperFactory.get (ApplicationModule_ProvideDbHelperFactory.java:10)
dagger.internal.DoubleCheck.get (DoubleCheck.java:47)
com.urtutors.eduwiser.data.AppDataManager_Factory.get (AppDataManager_Factory.java:43)
com.urtutors.eduwiser.data.AppDataManager_Factory.get (AppDataManager_Factory.java:11)
dagger.internal.DoubleCheck.get (DoubleCheck.java:47)
com.urtutors.eduwiser.di.module.ApplicationModule_ProvideDataManagerFactory.get (ApplicationModule_ProvideDataManagerFactory.java:30)
com.urtutors.eduwiser.di.module.ApplicationModule_ProvideDataManagerFactory.get (ApplicationModule_ProvideDataManagerFactory.java:10)
dagger.internal.DoubleCheck.get (DoubleCheck.java:47)
com.urtutors.eduwiser.MvpApp_MembersInjector.injectMembers (MvpApp_MembersInjector.java:38)
com.urtutors.eduwiser.MvpApp_MembersInjector.injectMembers (MvpApp_MembersInjector.java:9)
com.urtutors.eduwiser.di.component.DaggerApplicationComponent.inject (DaggerApplicationComponent.java:192)
com.urtutors.eduwiser.MvpApp.onCreate (MvpApp.java:55)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1013)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4730)
android.app.ActivityThread.access$1600 (ActivityThread.java:175)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1368)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:146)
android.app.ActivityThread.main (ActivityThread.java:5602)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
dalvik.system.NativeStart.main (NativeStart.java)

以下是firebase控制台的问题摘要 -

enter image description here

堆栈跟踪表明问题源自MvpApp.java,所以这里是第55行的错误源 -

Line 55

堆栈跟踪表明错误即将发生,因为它无法将dagger组件注入主应用程序 -

mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this)).build();

        mApplicationComponent.inject(this);

那么,任何人都可以帮我识别,调试或修复此问题。

我试着搜索周围的问题&发现了这个 -

Inject database in a ContentProvider with dagger

有一个建议的答案,将组件初始化移动到attachbasecontext方法而不是onCreate,我想尝试这个 解决方案,但我不明白如何获取YourMainApplication

的实例

致电YourMainApplication.get(context).inject(this);

1 个答案:

答案 0 :(得分:0)

日志还不够,但似乎您有循环依赖项注入。您可以检查课堂上的注射情况。

例如

public class A {
   @Inject 
   B classB; 

}

public class B {
   @Inject
   A classA; // this injection creates circular injection and also can cause stackoverflow exception
}

您必须避免这种情况。