New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module adapter could not be loaded #319

Closed
jedikriks opened this Issue Sep 25, 2013 · 7 comments

Comments

4 participants
@jedikriks

jedikriks commented Sep 25, 2013

So here is the Console output. I am using the same configuration as Android Bootstrap project, that is simple. I succeed to build and deploy the app to the device, but when i run it - it returns me an error always. Looks like it can not generate code for the annotations. I am using maven 3.X and JDK 1.7 (upd 40).

I already saw the same stacktrace on this issue tracker, but it did not help me at all.

I rly enjoy dagger features, but sofar i can not use them for real. Can you please help me with it?

Here is the stacktrace of the error:

E/AndroidRuntime( 9316): java.lang.RuntimeException: Unable to create application X: java.lang.IllegalStateException: Module adapter for X could not be loaded. Please ensure that code generation was run for this module.
E/AndroidRuntime( 9316): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4580)
E/AndroidRuntime( 9316): at android.app.ActivityThread.access$1300(ActivityThread.java:153)
E/AndroidRuntime( 9316): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
E/AndroidRuntime( 9316): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9316): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 9316): at android.app.ActivityThread.main(ActivityThread.java:5227)
E/AndroidRuntime( 9316): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9316): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 9316): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/AndroidRuntime( 9316): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/AndroidRuntime( 9316): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 9316): Caused by: java.lang.IllegalStateException: Module adapter for class X could not be loaded. Please ensure that code generatio
was run for this module.
E/AndroidRuntime( 9316): at dagger.internal.FailoverLoader.getModuleAdapter(FailoverLoader.java:41)
E/AndroidRuntime( 9316): at dagger.internal.Modules.getAllModuleAdapters(Modules.java:43)
E/AndroidRuntime( 9316): at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:167)
E/AndroidRuntime( 9316): at dagger.ObjectGraph$DaggerObjectGraph.plus(ObjectGraph.java:190)
E/AndroidRuntime( 9316): at Y.init(Injector.java:13)
E/AndroidRuntime( 9316): at Y.init(Injector.java:21)
E/AndroidRuntime( 9316): at X.onCreate(InnComClientApp.java:43)
E/AndroidRuntime( 9316): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
E/AndroidRuntime( 9316): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4577)
E/AndroidRuntime( 9316): ... 10 more
W/ActivityManager( 518): Force finishing activity my.package/.ui.MainActivity

@cgruber

This comment has been minimized.

Show comment
Hide comment
@cgruber

cgruber Oct 7, 2013

Collaborator

This entirely depends on your configuration. You must have some way to configure annotation processing. If it is in an Eclipse IDE, then you need to set up dagger-compiler to be in your "Factory path" for annotation processing in that project's properties. If you are using maven for command-line, then you need only ensure that dagger-compiler is an optional or provided dependency in the dependency list for your project. Otherwise, I'm not sure how to advise you, but you MUST generate module adapters at compile time or Dagger will not run. That is by design.

Collaborator

cgruber commented Oct 7, 2013

This entirely depends on your configuration. You must have some way to configure annotation processing. If it is in an Eclipse IDE, then you need to set up dagger-compiler to be in your "Factory path" for annotation processing in that project's properties. If you are using maven for command-line, then you need only ensure that dagger-compiler is an optional or provided dependency in the dependency list for your project. Otherwise, I'm not sure how to advise you, but you MUST generate module adapters at compile time or Dagger will not run. That is by design.

@cgruber cgruber closed this Oct 7, 2013

@cgruber

This comment has been minimized.

Show comment
Hide comment
@cgruber

cgruber Oct 7, 2013

Collaborator

I closed this issue, but if you want to post more about your build environment, we might be able to help. But this is not a dagger issue, it's a configuration issue on your side.

Alternately, I encourage you to post this on stack overflow, including information about your build system so folks can help you in a searchable forum where others might benefit.

Collaborator

cgruber commented Oct 7, 2013

I closed this issue, but if you want to post more about your build environment, we might be able to help. But this is not a dagger issue, it's a configuration issue on your side.

Alternately, I encourage you to post this on stack overflow, including information about your build system so folks can help you in a searchable forum where others might benefit.

@pabloogc

This comment has been minimized.

Show comment
Hide comment
@pabloogc

pabloogc Oct 9, 2013

Right now I'm facing the same issue running Android Studio 2.0.11, gradle 0.5.5 and dagger 1.1.0.

Following this solution: http://stackoverflow.com/questions/16683944/androidannotations-nothing-generated-empty-activity

I managed to generate the processed sources under build/sources/apt_generated. Now I need to figure out how to make gradle actually use this sources instead of the unprocessed ones (it builds fine, crashes at runtime) but I have no idea of what part of the build configuration I have to tweak for that. Some light here would be nice :)

pabloogc commented Oct 9, 2013

Right now I'm facing the same issue running Android Studio 2.0.11, gradle 0.5.5 and dagger 1.1.0.

Following this solution: http://stackoverflow.com/questions/16683944/androidannotations-nothing-generated-empty-activity

I managed to generate the processed sources under build/sources/apt_generated. Now I need to figure out how to make gradle actually use this sources instead of the unprocessed ones (it builds fine, crashes at runtime) but I have no idea of what part of the build configuration I have to tweak for that. Some light here would be nice :)

@cgruber

This comment has been minimized.

Show comment
Hide comment
@cgruber

cgruber Oct 9, 2013

Collaborator

Hmm. I'm not a gradle guy at all. @JakeWharton - do you have any insight?

My first thought is this - "processed sources" are only the additional adapters, they aren't "replacement sources". We generate new code, we don't modeify existing code. So all the normal .class files are legit - you just ALSO need to compile the apt_generated sources along with, and that seems like a gradle configuration issue that I don't know how to solve off-hand, sadly.

Collaborator

cgruber commented Oct 9, 2013

Hmm. I'm not a gradle guy at all. @JakeWharton - do you have any insight?

My first thought is this - "processed sources" are only the additional adapters, they aren't "replacement sources". We generate new code, we don't modeify existing code. So all the normal .class files are legit - you just ALSO need to compile the apt_generated sources along with, and that seems like a gradle configuration issue that I don't know how to solve off-hand, sadly.

@pabloogc

This comment has been minimized.

Show comment
Hide comment
@pabloogc

pabloogc Oct 9, 2013

Exactly, with processed sources I mean the code generated by dagger, not the whole source. I wasn't clear there.

I am 95% sure the problem is with gradle somehow not compiling or including the "apt_generated" classes in the apk. I guess the solution comes with modifying

android.sourceSets[variant].java.srcDirs += ... 

but no luck for now. If I get it working I'll post my build.gradle since I think this will be a recurring problem for newcomers.

Thank you for your help.

pabloogc commented Oct 9, 2013

Exactly, with processed sources I mean the code generated by dagger, not the whole source. I wasn't clear there.

I am 95% sure the problem is with gradle somehow not compiling or including the "apt_generated" classes in the apk. I guess the solution comes with modifying

android.sourceSets[variant].java.srcDirs += ... 

but no luck for now. If I get it working I'll post my build.gradle since I think this will be a recurring problem for newcomers.

Thank you for your help.

@pabloogc

This comment has been minimized.

Show comment
Hide comment
@pabloogc

pabloogc Oct 9, 2013

Well, finally I got it working. I really don't know if this is the best solution because of possible conflicts with flavors and things like that but for now it will do the trick.

buildscript {
   ...
}

apply plugin: 'android'

configurations {
    preprocess
}

dependencies {
    ...
    preprocess 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.squareup.dagger:dagger:1.1.0'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }
}

android.applicationVariants.all { variant ->
    //Where to place the generated code
    variant.ext.set("dagger_gen_${variant.dirName}", file("${project.buildDir}/source/dagger_gen/${variant.dirName}"))

    //Do the actual preprocessor things
    variant.javaCompile.doFirst {
        File out = variant.ext.get("dagger_gen_${variant.dirName}")
        out.mkdirs()
        variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.preprocess.getAsPath(),
                '-s', out
        ]
    }
}

pabloogc commented Oct 9, 2013

Well, finally I got it working. I really don't know if this is the best solution because of possible conflicts with flavors and things like that but for now it will do the trick.

buildscript {
   ...
}

apply plugin: 'android'

configurations {
    preprocess
}

dependencies {
    ...
    preprocess 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.squareup.dagger:dagger:1.1.0'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }
}

android.applicationVariants.all { variant ->
    //Where to place the generated code
    variant.ext.set("dagger_gen_${variant.dirName}", file("${project.buildDir}/source/dagger_gen/${variant.dirName}"))

    //Do the actual preprocessor things
    variant.javaCompile.doFirst {
        File out = variant.ext.get("dagger_gen_${variant.dirName}")
        out.mkdirs()
        variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.preprocess.getAsPath(),
                '-s', out
        ]
    }
}
@Kolyall

This comment has been minimized.

Show comment
Hide comment
@Kolyall

Kolyall Feb 26, 2016

@pabloogc Can you help me to make dagger:1.2.2 working on Android Studio? Your this last answer didn't help me...already tried. #520

Kolyall commented Feb 26, 2016

@pabloogc Can you help me to make dagger:1.2.2 working on Android Studio? Your this last answer didn't help me...already tried. #520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment