Android<中无法访问Dagger2生成的类。 5

时间:2015-11-20 21:44:11

标签: android dagger-2

我有一个使用Dagger2的项目,它补充了Autodagger。我的主要测试设备是装有KitKat和Lollipop的Genymotion模拟器,我在它们之间不知不觉地切换。

昨天我发现在应用程序启动时,在模拟器或带有4.x的真实设备上运行项目会导致以下异常:

   11-20 15:36:31.637 7189-7189/? E/AndroidRuntime: FATAL EXCEPTION: main
   java.lang.NoClassDefFoundError:   com.chiskosystems.debito.DebitoAppModule_ProvideRestAdapterFactory 
    at com.chiskosystems.debito.DaggerDebitoAppComponent.initialize(DaggerDebitoAppComponent.java:30)
    at com.chiskosystems.debito.DaggerDebitoAppComponent.<init>(DaggerDebitoAppComponent.java:19)
    at com.chiskosystems.debito.DaggerDebitoAppComponent.<init>(DaggerDebitoAppComponent.java:11)
    at com.chiskosystems.debito.DaggerDebitoAppComponent$Builder.build(DaggerDebitoAppComponent.java:72)
    at com.chiskosystems.debito.DebitoApp.setupComponent(DebitoApp.java:130)
    at com.chiskosystems.debito.DebitoApp.onCreate(DebitoApp.java:75)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:999)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4151)
    at android.app.ActivityThread.access$1300(ActivityThread.java:130)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

但是

find /path/to/project -name DebitoAppModule_ProvideRestAdapterFactory.java

显示结果。此外,该项目在L和M中运行良好。

proguard的规则

-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclassmembers

-keepattributes *Annotation*
-keepattributes Signature
-keepattributes InnerClasses

-keep class org.eclipse.mat.** { *; }
-keep class com.squareup.leakcanary.** { *; }

构建警告(这些只是一部分)

Note: com.google.android.gms.internal.zzlf$1: can't find dynamically referenced class com.facebook.login.LoginResult
Note: com.google.android.gms.internal.zzlf$1: can't find dynamically referenced class com.facebook.FacebookException
Note: com.google.android.gms.internal.zzlf$1: can't find dynamically referenced class com.facebook.AccessToken
Note: com.google.android.gms.internal.zzlf$2: can't find dynamically referenced class com.facebook.SessionState
Note: com.google.android.gms.maps.internal.zzy: can't find dynamically referenced class com.google.android.gms.maps.internal.CreatorImpl
Note: com.google.gson.internal.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class com.android.org.conscrypt.OpenSSLSocketImpl
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class android.net.TrafficStats
Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class android.net.Network
Note: retrofit.Platform: can't find dynamically referenced class android.os.Build
Note: retrofit.Platform: can't find dynamically referenced class rx.Observable
Note: android.support.multidex.MultiDexExtractor accesses a method 'apply()' dynamically
Note: android.support.v4.app.NotificationCompatJellybean accesses a declared field 'icon' dynamically
      Maybe this is program field 'android.support.design.R$attr { int icon; }'
      Maybe this is program field 'android.support.design.R$id { int icon; }'
      Maybe this is program field 'android.support.v4.app.NotificationCompat$Action { int icon; }'
      Maybe this is program field 'android.support.v7.appcompat.R$attr { int icon; }'
      Maybe this is program field 'android.support.v7.appcompat.R$id { int icon; }'
      Maybe this is program field 'android.support.v7.mediarouter.R$attr { int icon; }'
      Maybe this is program field 'android.support.v7.mediarouter.R$id { int icon; }'
      Maybe this is program field 'com.chiskosystems.debito.R$attr { int icon; }'
      Maybe this is program field 'com.chiskosystems.debito.R$id { int icon; }'
      Maybe this is program field 'io.fabric.sdk.android.services.settings.AppRequestData { io.fabric.sdk.android.services.settings.IconRequest icon; }'
      Maybe this is program field 'io.fabric.sdk.android.services.settings.AppSettingsData { io.fabric.sdk.android.services.settings.AppIconSettingsData icon; }'

我正在使用

compile 'com.google.dagger:dagger:2.1-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.1-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'

apt 'com.github.lukaspili.autodagger2:autodagger2-compiler:1.1'
compile 'com.github.lukaspili.autodagger2:autodagger2:1.1'
provided 'javax.annotation:jsr250-api:1.0'

切换构建工具也没有帮助。非常感谢任何可能出错的指针

修改

这些开始出现,并且在每个版本中都是不变的:

/home/chisko/AndroidStudioProjects/Debito/app/build/generated/source/apt/debug/com/chiskosystems/debito/ui/activities/activity/DaggerMainActivityComponent.java
Warning:(54, 75) [unchecked] unchecked method invocation: method create in class MainActivity_MembersInjector is applied to given types
required: MembersInjector<BaseActivity>,Provider<MainActivityPresenter>
found: MembersInjector,Provider<MainActivityPresenter>
Warning:(54, 76) [unchecked] unchecked conversion
required: MembersInjector<BaseActivity>
found:    MembersInjector
Warning:(54, 75) [unchecked] unchecked conversion
required: MembersInjector<MainActivity>
found:    MembersInjector
/home/chisko/AndroidStudioProjects/Debito/app/build/generated/source/apt/debug/com/chiskosystems/debito/ui/activities/splash/DaggerLoginActivityComponent.java
Warning:(54, 77) [unchecked] unchecked method invocation: method create in class LoginActivity_MembersInjector is applied to given types
required: MembersInjector<BaseActivity>,Provider<LoginPresenter>
found: MembersInjector,Provider<LoginPresenter>
Warning:(54, 78) [unchecked] unchecked conversion
required: MembersInjector<BaseActivity>
found:    MembersInjector
Warning:(54, 77) [unchecked] unchecked conversion
required: MembersInjector<LoginActivity>
found:    MembersInjector

0 个答案:

没有答案