【问题标题】:java.lang.IllegalStateException: Module adapterjava.lang.IllegalStateException:模块适配器
【发布时间】:2015-06-10 10:07:17
【问题描述】:

大家好,我想在 android 中使用 ObjectGraph 我正在使用以下

applicationGraph = ObjectGraph.create(getModules().toArray());
applicationGraph.inject(this);

但它给了我错误:

java.lang.RuntimeException: Unable to create application com.my.mynews.app.MyApplication: java.lang.IllegalStateException: Module adapter for class com.my.mynews.b.b could not be loaded. Please ensure that code generation was run for this module.
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4521)
        at android.app.ActivityThread.access$1500(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: java.lang.IllegalStateException: Module adapter for class com.my.mynews.b.b could not be loaded. Please ensure that code generation was run for this module.
        at a.a.j.a(Unknown Source)
        at a.a.j.a(Unknown Source)
        at a.a.x.b(Unknown Source)
        at a.a.i.a(Unknown Source)
        at a.a.z.a(Unknown Source)

我的 build.gradle 是这样的:

configurations {
 apt
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.+'
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.jakewharton:butterknife:5.0.+'
compile 'com.jakewharton.timber:timber:2.2.+'
compile 'com.squareup.dagger:dagger:1.2.+'
//provided 'com.squareup.dagger:dagger-compiler:1.2.+'
apt 'com.squareup.dagger:dagger-compiler:1.2.+'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.+'
compile 'com.fasterxml.jackson.core:jackson-core:2.4.+'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.+'
compile 'com.github.satyan:sugar:1.3'
compile 'com.pnikosis:materialish-progress:1.2'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.google.android.gms:play-services-analytics:7.0.0'

compile files('libs/volley.jar')
}

如果我取消注释上述依赖项中提供的注释并注释 apt 并生成 minifyEnabled false,那么它可以完美运行。但我想减少代码大小,因此我完成了minifyEnabled true 和应用程序崩溃。

任何建议将不胜感激。提前致谢

【问题讨论】:

    标签: android android-studio proguard


    【解决方案1】:

    我自己也遇到过类似的问题。不幸的是,Dagger 1.2+ 似乎不能很好地与 proguard 的 minifyEnabled 配合使用。所以我能找到的最佳选择是:

    1. 将 minifyEnabled 设置为 false 并处理它
    2. 升级到 Dagger 2.0(这是一个指南:http://frogermcs.github.io/dagger-1-to-2-migration/
    3. 有些人幸运地降级到 Dagger 1.0.1 并完全消除了 dagger-compiler (https://stackoverflow.com/a/23954164)。

    【讨论】:

      猜你喜欢
      • 2013-03-01
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多