Home » Android » android – Module adapter for class could not be loaded. Please ensure that code generation was run for this module

android – Module adapter for class could not be loaded. Please ensure that code generation was run for this module

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am getting this error when I try to run my App:

E/AndroidRuntime(2314): java.lang.RuntimeException: 
    Unable to create application in.mubble.billbytwo.GlobalApp: 
    java.lang.IllegalStateException: Module adapter for class 
    in.mubble.billbytwo.RootModule could not be loaded. 
    Please ensure that code generation was run for this module.

I think I am using Ant based build system I am not sure though, this is my first dagger project and I am on Eclipse IDE.

PS: I have already tried adding java-writer and dagger-compiler to factory paths as some other posts suggests but no luck.

here is a full stack trace:

FATAL EXCEPTION: main
Process: in.mubble.billbytwo, PID: 2314
java.lang.RuntimeException: 
    Unable to create application in.mubble.billbytwo.GlobalApp:    
    java.lang.IllegalStateException: Module adapter for class 
    in.mubble.billbytwo.RootModule could not be loaded. 
    Please ensure that code generation was run for this module.

at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
    .run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalStateException: 
   Module adapter for class 
   in.mubble.billbytwo.RootModule 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 in.mubble.billbytwo.Injector.init(Injector.java:13)
at in.mubble.billbytwo.Injector.init(Injector.java:24)
at in.mubble.billbytwo.GlobalApp.onCreate(GlobalApp.java:67)
at android.app.Instrumentation
    .callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)

Please Help how to resolve this.

How to&Answers:

It is important to be certain that code-generation is happening. Check your build directories to ensure that this class is actually being generated. I’ve not used Ant with Dagger, but for sure you need to ensure that dagger-compiler-${version}.jar is available to javac, so check in your classes folders and see if the code is being generated at all. If not, it’s a build configuration issue.

If it is, then you need to check your proguard configuration and ensure that it is keeping anything that inherits from ModuleAdapter and Binding. This is crucial because Dagger 1.x dynamically loads adapters, and therefore there is no static dependency in the code that can inform Proguard to leave it alone. So it is possible that Proguard has simply removed the adapter code, and therefore Dagger cannot load it.

(Note, this problem will be eliminated in Dagger 2)

Answer:

The same error message appears when you initialize Dagger’s object graph in the application class but then forget to register this application class in AndroidManifest.xml.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.andro">
    <application
        android:name=".MyDaggerApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
    </application>
</manifest>

Answer:

Well, for someone come to this thread later, I think this problem might be cause by the “typo” of Injector.init(Object).

Injector.init(this);

Should be

Injector.inject(this);

Answer:

Or just that you forgot to check the following option on Eclipse:

Java Compiler > Annotation Processing > Enable project specific settings

from Square Dagger IllegalStateException: Module adapter for class MyApplicationModule could not be loaded