As the title says, Dagger2 is not generating the Dagger* prefixed classes for my Android project. I looked at all other similar posts I could find but nothing helps. I'm trying to add it to an existing project, and I had some initial problems getting it to play nicely with data binding, but I seem to have sorted that out i.e. no compile errors on the data binding, and it generates code for it. I have also downloaded several example projects which work fine.
My top level graddle file has
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
while my build level has
apply plugin: 'com.neenbedankt.android-apt' .... final DAGGER_VERSION = '2.8' .... compile 'javax.inject:javax.inject:1' compile 'javax.annotation:javax.annotation-api:1.2' apt "com.google.dagger:dagger:$DAGGER_VERSION" compile "com.google.dagger:dagger:$DAGGER_VERSION" }
The component file is extremely simple
@Singleton @Component(modules = { AndroidModule.class }) public interface ApplicationComponent { void inject(MainActivity activity); }
The AndroidModule file contains
@Module public class AndroidModule { private final Context application; public AndroidModule(Application application) { this.application = application; } }
and the Application class has
import com.rockwellcollins.fsl.dagger.DaggerApplicationComponent; ... public class FslApplication extends Application { private static ApplicationComponent component; @Override public void onCreate() { super.onCreate(); component = DaggerApplicationComponent.builder() .androidModule(new AndroidModule(this)) .build(); } public static void inject(MainActivity target) { component.inject(target); } public ApplicationComponent getComponent() { return component; } }
and the output I get is
Information:Gradle tasks [clean, :android-sliding-layer-lib:Library:generateDebugSources, :android-sliding-layer-lib:Library:mockableAndroidJar, :android-sliding-layer-lib:Library:prepareDebugUnitTestDependencies, :android-sliding-layer-lib:Library:generateDebugAndroidTestSources, :android-sliding-layer-lib:Library:compileDebugSources, :android-sliding-layer-lib:Library:compileDebugUnitTestSources, :android-sliding-layer-lib:Library:compileDebugAndroidTestSources, :mobile:generateDebugSources, :mobile:mockableAndroidJar, :mobile:prepareDebugUnitTestDependencies, :mobile:generateDebugAndroidTestSources, :mobile:compileDebugSources, :mobile:compileDebugUnitTestSources, :mobile:compileDebugAndroidTestSources, :wear:generateDebugSources, :wear:generateDebugAndroidTestSources, :wear:mockableAndroidJar, :wear:prepareDebugUnitTestDependencies, :wear:compileDebugSources, :wear:compileDebugAndroidTestSources, :wear:compileDebugUnitTestSources] Warning:WARNING: Dependency org.json:json:20131018 is ignored for debug as it may be conflicting with the internal version provided by Android. Warning:WARNING: Dependency org.json:json:20131018 is ignored for release as it may be conflicting with the internal version provided by Android. Warning:View field aircraftList collides with a variable or import Warning:View field groundList collides with a variable or import C:\Git\android\mobile\src\main\java\com\rockwellcollins\fsl\FslApplication.java Error:(7, 38) error: cannot find symbol class DaggerApplicationComponent Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details. Information:BUILD FAILED
And as I said, no code gets generated at all for the Dagger stuff. If anyone can point out what the problem is, I would be very grateful.