gpt4 book ai didi

android - 方形 Dagger IllegalStateException : Module adapter for class MyApplicationModule could not be loaded

转载 作者:可可西里 更新时间:2023-11-01 18:46:46 26 4
gpt4 key购买 nike

我正在为我的 Android 项目使用 eclipse 和 Dagger 1.2.2。我设法用 Dagger 实现了一个测试应用程序。但是通过我的“真实”应用程序,我得到:

java.lang.RuntimeException:无法创建应用程序 app.MyApplication:java.lang.IllegalStateException:无法加载类 app.MyApplicationModule 的模块适配器。请确保已为此模块运行代码生成。:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to create application app.MyApplication: java.lang.IllegalStateException: Module adapter for class app.MyApplicationModule could not be loaded. Please ensure that code generation was run for this module.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4687)
at android.app.ActivityThread.access$1400(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Module adapter for class app.MyApplicationModule could not be loaded. Please ensure that code generation was run for this module.
at dagger.internal.FailoverLoader$1.create(FailoverLoader.java:45)
at dagger.internal.FailoverLoader$1.create(FailoverLoader.java:40)
at dagger.internal.Memoizer.get(Memoizer.java:56)
at dagger.internal.FailoverLoader.getModuleAdapter(FailoverLoader.java:57)
at dagger.internal.Modules.loadModules(Modules.java:43)
at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:174)
at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:138)
at dagger.ObjectGraph.create(ObjectGraph.java:129)
at app.MyApplication.onCreate(MyApplication.java:17)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4684)
... 10 more

这是MyApplication.java:

public class MyApplication extends Application implements InjectableApplication {
private ObjectGraph objectGraph;

@Override
public void onCreate() {
super.onCreate();

objectGraph = ObjectGraph.create(new MyApplicationModule(this));
objectGraph.inject(this);
}

@Override
public void inject(Object o) {
objectGraph.inject(o);
}

public ObjectGraph getObjectGraph() {
return objectGraph;
}
}

这是我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="app.MyApplication" >
<activity
android:name="app.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

我还将 Dagger jar 包含到构建路径和工厂路径中。

最佳答案

对于可能像我一样遇到此问题的任何人。我面临的问题是我没有在我的 gradle 构建文件中添加依赖项以允许 dagger 在我的类之上进行代码生成:

添加这个:

apt 'com.squareup.dagger:dagger-compiler:1.2.2'

更新:如果你不知道 apt 插件在哪里,你可以在你的项目 gradle 文件中安装它。我的依赖项如下所示:

dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4+'
}

关于android - 方形 Dagger IllegalStateException : Module adapter for class MyApplicationModule could not be loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27114578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com