google / dagger Goto Github PK
View Code? Open in Web Editor NEWThis project forked from square/dagger
A fast dependency injector for Android and Java.
Home Page: https://dagger.dev
License: Apache License 2.0
This project forked from square/dagger
A fast dependency injector for Android and Java.
Home Page: https://dagger.dev
License: Apache License 2.0
Any dates?
Repro instructions to follow.
I know you guys are still in the process of making the examples, but at this point they don't work at all. One such example is that https://github.com/google/dagger/blob/master/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/AbstractActivityComponent.java has a different class name than the file.
This makes determining how everything is supposed to work fairly difficult if you don't already understand the intricacies of the Dagger2 implementation.
I have reported issue on jetbrains bug tracker https://youtrack.jetbrains.com/issue/KT-6446
Basically, MemberInjector rely on property assignment. Even if Kotlin's property is public only setter is available from the java class.
Maybe you can provide some workarounds for this?
In the android-simple example a parent class (https://github.com/google/dagger/blob/master/examples/android-simple/src/main/java/com/example/dagger/simple/DemoActivity.java) is doing the injection and the children class (https://github.com/google/dagger/blob/master/examples/android-simple/src/main/java/com/example/dagger/simple/ui/HomeActivity.java) is expected to de injected after the call to super.
It does not seem to work as the inject method from the component called is the one from the parent class skipping any member injection for the child class.
Compilation of a generated component currently fails if a component or provider method return type has the same simple name as a nested type of the component, or that of its supers.
Failing tests
@Test public void nameCollision_componentMethodWithSuperTypeMember() {
JavaFileObject injectableTypeFile = JavaFileObjects.forSourceLines("test.SomeInjectableType",
"package test;",
"",
"final class SomeInjectableType {",
" @javax.inject.Inject SomeInjectableType() {}",
"}");
JavaFileObject superType = JavaFileObjects.forSourceLines("test.Supertype",
"package test;",
"",
"interface Supertype {",
" interface SomeInjectableType{}",
"}");
// Generated code should retain the fully-qualified return type.
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
"package test;",
"",
"@dagger.Component",
"interface SimpleComponent extends Supertype {",
" test.SomeInjectableType someInjectableType();",
"}");
assert_().about(javaSources()).that(ImmutableList.of(
injectableTypeFile, superType, componentFile))
.processedWith(new ComponentProcessor())
.compilesWithoutError();
}
@Test public void nameCollision_componentMemberWithSuperTypeMethod() {
JavaFileObject injectableTypeFile = JavaFileObjects.forSourceLines("test.SomeInjectableType",
"package test;",
"",
"final class SomeInjectableType {",
" @javax.inject.Inject SomeInjectableType() {}",
"}");
JavaFileObject superType = JavaFileObjects.forSourceLines("test.Supertype",
"package test;",
"",
"interface Supertype {",
" SomeInjectableType someInjectableType();",
"}");
// Generated code should see the name conflict and fully-qualify the component's return type.
JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.SimpleComponent",
"package test;",
"",
"@dagger.Component",
"interface SimpleComponent extends Supertype {",
" interface SomeInjectableType{}",
"}");
assert_().about(javaSources()).that(ImmutableList.of(
injectableTypeFile, superType, componentFile))
.processedWith(new ComponentProcessor())
.compilesWithoutError();
}
The reason the generated type fails compilation is that it doesn't fully qualify types that collide.
Ex.
public SomeInjectableType someInjectableType() {
which should be fully qualified like so:
public test.SomeInjectableType someInjectableType() {
As discussed.
When I build my project I see a note:
Generating a MembersInjector or Factory for com.demo.MainActivity. Prefer to run the dagger processor over that class instead.
What can I do to make Dagger "happy" and get rid of that note or should I ignore it?
My code is very simple. I skipped some irrelevant parts.
Application
public class BaseApplication extends Application {
@Singleton
@Component(modules = {AndroidModule.class, FontModule.class}) public interface ApplicationComponent {
void inject(MainActivity mainActivity);
}
private static ApplicationComponent graph;
@Override public void onCreate() {
super.onCreate();
graph = Dagger_BaseApplication_ApplicationComponent.builder()
.androidModule(new AndroidModule(this)).fontModule(new FontModule())
.build();
}
public static ApplicationComponent getGraph() {
return graph;
}
}
MainActiivty
override fun onCreate(savedInstanceState: Bundle?) {
super<BaseActivity>.onCreate(savedInstanceState)
....
BaseApplication.getGraph().inject(this)
}
Sorry to bother, I know it's coming and everything, but could anyone give any example of how to use @MapKey
?
build.gradle
// ...
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
compile 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
$./gradlew build --stacktrace
Stack trace:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':weheartit:compileDefaultFlavorBetaJava'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:258)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.HandleCancel.execute(HandleCancel.java:36)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:30)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:52)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:154)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at com.sun.tools.javac.main.Main.compile(Main.java:469)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:45)
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:97)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:50)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:36)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:127)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:113)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:90)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:235)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:222)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 69 more
Caused by: java.lang.NullPointerException
at dagger.internal.codegen.dagger1.InjectAdapterProcessor.validateInjectable(InjectAdapterProcessor.java:157)
at dagger.internal.codegen.dagger1.InjectAdapterProcessor.findInjectedClassNames(InjectAdapterProcessor.java:118)
at dagger.internal.codegen.dagger1.InjectAdapterProcessor.process(InjectAdapterProcessor.java:85)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
... 87 more
I'm getting the following runtime error using Dagger 2 while trying to run Instrumentation tests (using Espresso). In my project, I create an instance of a Component in the Application class and use that instance to inject values into Activities, Fragments, etc.. The AndroidComponent constructor requires a Context and the Application class passes an instance of itself. I have debug and release build variants which run fine, but the Instrumentation Runner (or GoogleInstrumentationTestRunner in this case) causes this strange error.
Logcat
AndroidRuntime E FATAL EXCEPTION: main
E Process: com.project.android.dev, PID: 3556
E java.lang.NoClassDefFoundError: com/project/android/DataModule$$ProvidesApiFactory
E at com.project.android.Dagger_AndroidComponent.initialize(Dagger_AndroidComponent.java:65)
E at com.project.android.Dagger_AndroidComponent.<init>(Dagger_AndroidComponent.java:57)
E at com.project.android.Dagger_AndroidComponent.<init>(Dagger_AndroidComponent.java:31)
E at com.project.android.Dagger_AndroidComponent$Builder.build(Dagger_AndroidComponent.java:117)
E at com.project.android.AndroidComponent$Initializer.init(AndroidComponent.java:21)
E at com.project.android.App.onCreate(App.java:51)
E at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
E at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
E at android.app.ActivityThread.access$1500(ActivityThread.java:135)
E at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E at android.os.Handler.dispatchMessage(Handler.java:102)
E at android.os.Looper.loop(Looper.java:136)
E at android.app.ActivityThread.main(ActivityThread.java:5017)
E at java.lang.reflect.Method.invokeNative(Native Method)
E at java.lang.reflect.Method.invoke(Method.java:515)
E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E at dalvik.system.NativeStart.main(Native Method)
E Caused by: java.lang.ClassNotFoundException: Didn't find class "com.project.android.DataModule$$ProvidesApiFactory" on path: DexPathList[[zip file "/system/framewo
rk/android.test.runner.jar", zip file "/data/app/com.project.android.dev.test-2.apk", zip file "/data/app/com.project.android.dev-2.apk"],nativeLibraryDirectories=[
/data/app-lib/com.project.android.dev.test-2, /data/app-lib/com.project.android.dev-2, /vendor/lib, /system/lib]]
E at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
E at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
E ... 18 more
Process 3556 ended
Below is basically what the classes in question consist of. The design is pretty much straight from the samples.
The main gist of App.java
public class App extends android.app.Application {
private AndroidComponent component;
@Override
public void onCreate() {
super.onCreate();
component = AndroidComponent.Initializer.init(this.getApplicationContext());
component().inject(this);
}
public AndroidComponent component() {
return component;
}
}
The main gist of AndroidComponent.java
@Singleton
@Component(modules = { DataModule.class })
public interface AndroidComponent {
void inject(BaseActivity activity);
void inject(App application);
void inject(BaseFragment fragment);
public final static class Initializer {
static AndroidComponent init(Context app) {
return Dagger_AndroidComponent.builder()
.dataModule(new DataModule(app))
.build();
}
}
}
The main gist of DataModule.java
public class DataModule {
private final Context application;
public DataModule(Context application) {
this.application = application;
}
@Provides @Singleton
Api providesApi() {
return new Api(application);
}
}
Is there any special reason for using different version of auto-service
1.0-rc1 because I get compilation error on Windows.
[ERROR] FATAL ERROR: java.lang.IllegalArgumentException: Invalid relative name: META-INF\services\javax.annotation.processing.Processor
The reason is auto-service rc1
does not have following fix google/auto@4ccfabf which is almost a year ago. The fix is to use 1.0-SNAPSHOT
.
Hi,
I think it's a problem with my environment (java 1.7.0_51, 64 bit, mac os 10.10), but I'm using Android Studio and tried to setup a simple android sample application with dagger 2 as dependency injection framework.
My compiler can not resolve the @Generated
annotation in class path (import javax.annotation.Generated;
) which is used in all dagger generated classes.
My gradle build file looks like this:
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
provided 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
Any idea what could be wrong?
Do I have to add the javax annotation dependency to my build.gradle
?
I've been looking for upgrade docs for dagger 1.x to dagger 2.x for the last hour and I couldn't find anything. Are these documents planned any time soon?
Hi,
I have a mixed Java/Groovy project that I was interested in using Groovy in, for which I am using the groovy-eclipse-compiler via the maven compiler plugin.
It seems that this is somehow incompatible; I extracted the simple example from it's parent pom, got it to compile, then attempted to switch compilers and the moment I did so maven stopped generating sources.
Are there any plans to support such use of Dagger 2? Or is there a better way to utilise Dagger 2 in a mixed Java/Groovy project being built using Maven.
Component says "interface or abstract class", but only interfaces are currently supported. Is this a gap or an intent?
A new AndroidStudio 1.1 version introduced the unit testing support. This URL http://tools.android.com/tech-docs/unit-testing-support provides step-by-step instruction how to setup IDE to run JUnit tests for Android project.
android-apt plugin by Hugo Visser works nice in assisting of creation Dagger2 generated files for usual Android code but unfortunately there is no generated files for any JUnit test class. I tried to configure dependency like androidTestApt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT' (and tried to specify 'testCompile' and 'provided' too) according to android-apt plugin documentation but without success.
I think the problem is in different sources directory for Unit tests - it's src/test/java instead of src/androidTest/java that used by android instrumentation tests.
Can you please provide any help how to resolve this trouble? I can't understand where is the problem: in the wrong project configuration, a bug in new Android Studio's JUnit tests feature, something wrong in Dagger2 or in android-apt plugin. When needed, I can provide the simple AndroidStudio project to reproduce the trouble.
Thanks in advance.
With set and map declaration moving to its own annotation, @Provides
can be argued as useless, redundant information. All non-private, non-static methods would become providers. Public methods on modules which are not providers seems like an anti-pattern or erroneous. This also brings a stronger corollary to components.
I briefly discussed this with @gk5885 last week.
In attempting to use a circular dependency (with Lazy
, as appears to be possible in dagger1), I found a case where a StackOverflowError occurs when attempting to report the cycle to the user.
This example is striped down as much as possible - removing or simplifying any further appears to make this bug go away.
public class LazyCycleBroken {
@Component
public static interface MyComponent {
App app();
}
public static class App {
@Inject
Bar bar;
@Inject
public App() {
}
}
public static class Bar {
@Inject
Lazy<Foo> lazyFoo;//in dagger1 this is legal, in dagger2 cycles of any kind are forbidden
@Inject
public Bar() {
}
}
public static class Foo {
@Inject
Bar bar;
@Inject
public Foo() {
}
}
}
Useful part of the stack trace:
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.reportCycle(BindingGraphValidator.java:195)
at dagger.internal.codegen.BindingGraphValidator.access$300(BindingGraphValidator.java:34)
at dagger.internal.codegen.BindingGraphValidator$1.visitResolvedBinding(BindingGraphValidator.java:72)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:234)
at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:54)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:71)
Would be really useful to get more realistic examples, especially for webframeworks.
Has anyone attempted to get Dagger2 working with Jersey?
I'm attempting to compile my project and it's running into an IllegalStateException in the BuildingGraphValidator on line 475. There's no error message in that exception so I'm not really sure what's failing or why.
Looking at the code it looks like it has to do with validating the scope of the components. I do know that I have a component of scope A depending on a component of scope B (basically one is a singelton-level scope and the other is an activity-level scope). I'm going to guess that the issue is a misplaced or missing scope annotation, but the error message is blank so it doesn't give much of an indicator.
Hey, due to the "improvements" introduced in the latest SNAPSHOT release, like #108, I'd like to ask one question.
Since Dagger2 is feature complete and you're squashing bugs and updating some docs, why don't you guys release current version as something like v2.0-beta1, or even 2.0 and then, when release bugfix versions, 2.0-beta2 or 2.0.1?
Continuing releasing under 2.0-SNAPSHOT leads all current users to failures occurring on random machines, where Gradle decided to silently update SNAPSHOT dependencies. Actually, it's the same situation as it was with ADT. When introducing new build system, based on Gradle, Xavier from Google said that they will release every build tools with particular version so that any update won't break projects which are built by previous version. Then, it's up to developer when he or she want to upgrade to new version.
IMHO it's high time to release Dager2 with concrete version, isn't it?
Sample code:
public interface Injector<T> {
void inject(T t);
}
@Component interface Lalala extends Injector<MyView> {
}
This does not compile because Injector is parameterized.
Two things to consider here:
The error below is thrown at compilation time. It's a "valid" error, but it needs to be more human readable.
I understand why this isn't allowed right now: it's more work AND it's useless as soon as you have more than one type to inject from that component. However, in our Android apps, we create one component per custom view (I can explain why if needed) and in most cases have only one entry point. We hide components in a ContextWrapper, and it'd be nice to return a Injector from that context wrapper and use that from the view.
Caused by: java.lang.IllegalArgumentException
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:108)
at dagger.internal.codegen.InjectBindingRegistry.getOrFindMembersInjectionBinding(InjectBindingRegistry.java:198)
at dagger.internal.codegen.BindingGraph$Factory$RequestResolver.resolve(BindingGraph.java:318)
at dagger.internal.codegen.BindingGraph$Factory.create(BindingGraph.java:155)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:70)
at dagger.internal.codegen.ComponentProcessor.process(ComponentProcessor.java:146)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
... 68 more
When adding both libraries the compilation doesn't work anymore. I've also opened an issue on the AutoFacotry tracker but the problem seems to be more than the Dagger 1 dependency.
I think this is related to the latest google/auto snapshot pushed today. But dagger-compiler
throws the following error:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJava'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
at com.sun.tools.javac.main.Main.compile(Main.java:469)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:42)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:35)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:97)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:50)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:36)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:158)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:138)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:92)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:235)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:222)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 54 more
Caused by: java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
at dagger.internal.codegen.ComponentDescriptor$Factory.create(ComponentDescriptor.java:124)
at dagger.internal.codegen.ComponentDescriptor$Factory.forComponent(ComponentDescriptor.java:114)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:74)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:222)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
... 72 more
They can break the contract of a component's scope otherwise.
@Module
public class NetworkModule {
@Provides @Singleton
OkHttpClient provideOkHttpClient() {
return new OkHttpClient();
}
}
@Singleton
@Component(modules = NetworkModule.class)
interface ApiComponent {
OkHttpClient client();
default TwitterApi api() {
return new TwitterApi(client());
}
}
ApiComponent apiComponent = Dagger_ApiComponent.create();
System.out.println("true? => " + apiComponent.api() == apiComponent.api());
true? => false
With this, default methods would only be used in custom implementations of a component interface.
hi, does somebody know if u2020 has a chance to be updated with dagger2?
Class<?>[] injects() default { };
Class<?>[] staticInjections() default { };
boolean overrides() default false;
Class<?> addsTo() default Void.class;
boolean complete() default true;
boolean library() default true;
Hi
We previously had one huge activity scoped component that handled pretty much everything, with dagger2 we wanted to make components per feature where that's possible. This allows us to make a lot of code package local instead of public. This resulted in .. 42 component classes, slightly more than we had hoped.
A lot of these just exist to inject very basic things, some base stuff that we use almost everywhere. For example:
@Component(dependencies = FinnApplicationComponent.class)
interface LastSearchesComponent {
void inject(LastSearchesContentProvider target);
]
Would it be possible to annotate LastSearchesContentProvider with something to generate this file rather than creating seperate files for it? Our only alternative is to make 50+ classes public and create inject functions for them in FinnApplicationComponent. This clutters the code and produces a ton of package cycles.
Hi,
Yesterday I finished migrating my project to Dagger2 from Dagger1, except a few errors with @singleton annotations. I commented all of them, project was built and successfully launched on Android emulator and I leave the resolving an issue with singleton annotation for today's evening. Unfortunately today, when I uncommented back @singleton annotations in the application-wide @component interface and tried to build the project, it fails with the following message:
Error:Execution failed for task ':nt2:compileDebugJava'.
java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
Attempts to clean, rebuild, invalidate project, comment @singleton annotations back was unsuccessful. I can delete AppComponent.java file, but in this case compiler complains for missed class that it can resolve in module, application and activity classes.
I noticed that MoreTypes is a class of com.google.auto project. Checked its sources on GitHub and can't find the method asTypeElements() with 2 arguments of type Types and Iterable. Looks like AndroidStudio downloaded the (latest?) snapshot version of com.google.auto project to resolve dependency required by Dagger2, but two-argument version of AsTypeElements method is no more present there.
Can you please provide any solution to fix this issue?
As of the latest snapshot release, I'm running into the following build exception. I can work around this by removing the generic declaration from InjectedBaseActivityTest
, but I believe this should be supported.
Note: Generating a MembersInjector or Factory for com.circle.testexample.InjectedBaseActivityTest. Prefer to run the dagger processor over that class instead.
/Users/bryan/code/dagger-instrumentation-example/app/src/debug/java/com/circle/testexample/InjectedBaseActivityTest.java:10: error: Could not generate [com.circle.testexample.InjectedBaseActivityTest$$MembersInjector]: Attempt to recreate a file for type com.circle.testexample.InjectedBaseActivityTest$$MembersInjector.
public class InjectedBaseActivityTest<T extends BaseActivity> extends ActivityInstrumentationTestCase2<T> {
^
1 error
:app:compileDebugJava FAILED
FAILURE: Build failed with an exception.
The relevant classes are.
@Singleton
@Component(modules = {DebugDataModule.class})
public interface Graph {
void inject(BaseActivity activity);
void inject(InjectedBaseActivityTest test);
public final static class Initializer {
public static Graph init(boolean mockMode) {
return Dagger_Graph.builder()
.debugDataModule(new DebugDataModule(mockMode))
.build();
}
}
}
public class InjectedBaseActivityTest<T extends BaseActivity> extends ActivityInstrumentationTestCase2<T> {
@Inject
Api mockApi;
public InjectedBaseActivityTest(Class<T> activityClass) {
super(activityClass);
}
@Override
protected void setUp() throws Exception {
super.setUp();
App app = (App) getInstrumentation().getTargetContext().getApplicationContext();
app.graph().inject(this);
}
}
public class MainActivityTest extends InjectedBaseActivityTest<MainActivity> {
public MainActivityTest() {
super(MainActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
// tests
}
Updating the component's inject method to void inject(InjectedBaseActivityTest<? extends BaseActivity> test);
produces the following build exception.
/Users/bryan/code/dagger-instrumentation-example/app/build/generated/source/apt/debug/com/circle/testexample/Dagger_Graph.java:61: error: method create in class InjectedBaseActivityTest$$MembersInjector<T#2> cannot be applied to given types;
this.injectedBaseActivityTestMembersInjector = InjectedBaseActivityTest$$MembersInjector.create(activityInstrumentationTestCase2MembersInjector, provideApiProvider);
^
required: MembersInjector<ActivityInstrumentationTestCase2<T#1>>,Provider<Api>
found: MembersInjector<ActivityInstrumentationTestCase2<? extends BaseActivity>>,Provider<Api>
reason: no instance(s) of type variable(s) T#1 exist so that argument type MembersInjector<ActivityInstrumentationTestCase2<? extends BaseActivity>> conforms to formal parameter type MembersInjector<ActivityInstrumentationTestCase2<T#1>>
where T#1,T#2 are type-variables:
T#1 extends BaseActivity declared in method <T#1>create(MembersInjector<ActivityInstrumentationTestCase2<T#1>>,Provider<Api>)
T#2 extends BaseActivity declared in class InjectedBaseActivityTest$$MembersInjector
1 error
:app:compileDebugJava FAILED
FAILURE: Build failed with an exception.
The complete example can be found at https://github.com/bryanstern/dagger-instrumentation-example/
This issue appeared with snapshot release 13.
Since the snapshot release of yesterday, i cannot compile my Components anymore. I have a setup similar to the 'android-activity-graphs' example.
Since today I cannot compile anymore, with the following:
/src/main/java/di/Component2.java
Error:(17, 12) error: This @singleton component cannot depend on scoped components:
@singleton di.Component1
/src/main/java/di/Component3.java
Error:(17, 12) error: This @singleton component cannot depend on scoped components:
@singleton di.Component2
It seems @singleton suddenly doesn't likes itself anymore.
The compiler should be self-contained so as to not cause dependency resolution problems with our upstream library usage choices.
Cross filed for v1 at square#451.
Error:(72, 5) java: cannot find symbol
symbol: method assert_()
location: class dagger.internal.MapProviderFactoryTest
Failed to execute goal on project dagger: Could not resolve dependencies for project com.google.dagger:dagger:jar:2.0-SNAPSHOT: Could not find artifact com.google.truth:truth:jar:1.0-SNAPSHOT -
The android-activity-graphs example cannot generate dagger sources based on the annotations.
inputFiles.lst
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeActivity.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/DemoApplication.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ApplicationComponent.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/ActivityTitleController.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeFragment.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ui/HomeComponent.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/DemoApplicationModule.java
dagger/examples/android-activity-graphs/target/generated-sources/r/com/example/dagger/activitygraphs/BuildConfig.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/PerActivity.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/AbstractActivityComponent.java
dagger/examples/android-activity-graphs/src/main/java/com/example/dagger/activitygraphs/ActivityModule.java
createdFiles.lst is empty.
Apologies if this is a dup (couldn't see an open issue).
Is there any standard way to do testing. Overriding @Provides
or extending module classes.
I know it was discussed by Jake at Devvox that it still needs fleshing out.
What are the current thoughts? This for me is the only real blocker. I can work around the limitations, but it feels like yak-shaving.
I'm experimenting with the latest snapshot of Dagger 2 and I'm getting this error while building:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJava'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
[snip]
Caused by: java.lang.NullPointerException
at com.google.auto.common.MoreElements.asType(MoreElements.java:99)
at dagger.internal.codegen.BindingGraphValidator.reportMissingBinding(BindingGraphValidator.java:156)
at dagger.internal.codegen.BindingGraphValidator.access$000(BindingGraphValidator.java:39)
at dagger.internal.codegen.BindingGraphValidator$1.visitResolvedBinding(BindingGraphValidator.java:70)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:299)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:61)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:71)
at dagger.internal.codegen.ComponentProcessor.process(ComponentProcessor.java:146)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
... 66 more
I'm sure I have a missing binding, but surely would appreciate Dagger telling me which one. :)
Integrate Google's CLA checking with the github project.
public class Foo {
@Component
public class Bar {}
}
produces Dagger_Foo$Bar
. AutoValue produces names in the form Dagger_Foo_Bar
which seems much more desirable.
In Dagger 1, you could call inject
from a base class and have all dependencies satisfied for subclasses:
class BaseActivity extends Activity {
@Inject Foo foo;
public void onCreate(Bundle savedInstanceState) {
objectGraph().inject(this);
}
}
class MainActivity extends BaseActivity {
@Inject Bar bar;
@Override void onCreate(Bundle savedInstanceState) {
super.onCreate();
// both foo and bar will be available here
}
}
This has changes in Dagger 2; injecting from a base class will only satisfy the base class's dependencies, not it's subclasses's.
class BaseActivity extends Activity {
@Inject Foo foo;
public void onCreate(Bundle savedInstanceState) {
component().inject(this);
}
}
class MainActivity extends BaseActivity {
@Inject Bar bar;
@Override void onCreate(Bundle savedInstanceState) {
super.onCreate();
// only foo is available here, not bar
}
}
Is there a recommended pattern for injecting dependencies from a base class, rather than calling inject in each of the subclasses?
(This is the Dagger equivalent to google/auto#187)
Motivation: I am trying to get Guava to start relying on the GWT compiler's new automatic stripping, rather than doing its own @GwtIncompatible
stripping. This means that the Java compilation that we do for GWT is now seeing @GwtIncompatible
classes. The GWT compiler proper then ignores then. But because javac saw them, Dagger generated Factory
classes for those with @Inject
constructors. Those Factory
classes refer back to the @GwtIncompatible
original, which the GWT compiler can't see. We get a compilation error:
[ERROR] Errors in 'blahblah.jar/com/google/common/time/DefaultSleeper$$Factory.java'
[ERROR] Line 12: The constructor DefaultSleeper() is not visible
(Google developers can check out the full results.)
A solution (I think) is for Dagger to annotate the Factory
class as @GwtIncompatible
if the original class (or any enclosing class) is so annotated. Does this sound reasonable?
I'm not sure if there currently is no way to @Inject a regular class instead of an interface, but if you try to give a class that doesn't implement anything an @Inject-constructor, it gets placed in a directory called "ClassName$$Factory" instead of the directory corresponding to its package declaration (for example, I have a class Thing that sits in com/package/Thing.java, and it looks like
public class Thing {
@Inject public Thing() {}
}
and it produces a class Thing$$Factory that sits in Thing$$Factory/Thing$$Factory.java instead of com/package/Thing$$Factory.java and looks like
package com.package; // Note the correct package declaration
import dagger.Factory;
import javax.annotation.Generated;
@generated("dagger.internal.codegen.ComponentProcessor")
public enum Thing$$Factory implements Factory {
INSTANCE;
@OverRide
public Thing get() {
return new Thing();
}
}
Android does not ship with the javax.annotation
package so the generated code with @Generated
does not compile.
One can add the dependency manually eg:
compile 'javax.annotation:javax.annotation-api:1.2-b01'
These are not valid, make them an error.
My project has a dependency on an event bus that I should be injecting in several places. Given that it is a simple dependency, I wanted to add @Inject and @singleton to the constructor
Then I'm using it to inject a field and a module, but they're receiving different instances
The solution was migrating the injection to a module to allow @singleton, but I was wondering if constructor singletons would be available too.
Hi guys, I've used dagger for android development liked it very much and intending to use it for the server-side as well. My project has a hot redeployment requirement and I wonder could I use Dagger somehow in OSGI environment. I've tried it with Apache Karaf and it's doesn't works.
Could someone clarify is Dagger an OSGI ready?
square.github.com/dagger
instead of https://google.github.io/dagger/ (the link in the README is OK though)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.