I have a public project where I'm experimenting with the latest libraries for Android, and which is targeting Nougat (minSdk 24). It's using Jack and the new annotationProcessor (and androidTestAnnotationProcessor). I have the following:
// In main sourceSet
@Singleton
@Component(modules = PresenterModule.class)
public interface StopwatchComponent {
void inject(StopwatchFragment stopwatchFragment);
}
// In androidTest sourceSet
@Singleton
@Component(modules = TestModule.class)
public interface TestStopwatchComponent extends StopwatchComponent {
void inject(StopwatchFragmentTest test);
}
When I run ./gradlew assembleDebugAndroidTest, I get the following error:
* What went wrong:
Execution failed for task ':app:transformJackWithJackForDebugAndroidTest'.
> com.android.jack.ir.JNodeInternalError: java.lang.Exception: java.lang.IllegalArgumentException: element public abstract void inject(com.autonomousapps.reactivestopwatch.ui.StopwatchFragment) is not a member of the containing type com.autonomousapps.reactivestopwatch.di.TestStopwatchComponent nor any of its superclasses
If I change TestStopwatchComponent as follows, the error goes away:
@Singleton
@Component(modules = TestModule.class)
public interface TestStopwatchComponent extends StopwatchComponent {
void inject(StopwatchFragment fragment); // new
void inject(StopwatchFragmentTest test);
}
I don't believe this should be necessary. After all, TestStopwatchComponent extends StopwatchComponent, which defines that injection. I've used this pattern in other projects, and it works fine. Either I'm overlooking an obvious bug, or there's a real issue in dagger/jack/annotationProcessor. I appreciate any help you can offer.
I actually ran into this issue yesterday when attempting to upgrade to java 8 in android. I am using a base ActivityComponent(with Activity injector) interface that I extend from smaller components(ChildComponent) interfaces like this:
@ActivityScope
@Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
public interface ActivityComponent {
// Exposed to sub-graphs.
Activity activity();
}
@ActivityScope
@Component(
modules = {ActivityModule.class, ControlsModule.class},
dependencies = ApplicationComponent.class
)
public interface ChildComponent extends ActivityComponent {
void inject(ChildActivity activity);
ChildPresenter presenter();
}
I am using the latest stable android plugin 2.2.0 and Dagger 2.7 release with the annotationProcessor notation instead of apt plugin from the android plugin.
To me it looks like a bug in the way dagger is doing validation with the jack compiler, something doesn't correctly interpret interface inheritance correctly, I also tried using component dependency from the ChildComponent and removing the extend portion and still get the same message.
@ActivityScope
@Component(
modules = {ActivityModule.class, ControlsModule.class},
dependencies = ActivityComponent.class
)
public interface ChildComponent {
void inject(ChildActivity activity);
ChildPresenter presenter();
}
Here is the stacktrace I see in gradle CLI:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformJackWithJackForMockDebug'.
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:66)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
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.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.RuntimeException: com.android.jack.ir.JNodeInternalError: java.lang.Exception: java.lang.IllegalArgumentException: element public abstract android.app.Activity activity() is not a member of the containing type .ChildComponent nor any of its superclasses
at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:126)
at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1852)
at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJack(AndroidBuilder.java:1679)
at com.android.build.gradle.internal.transforms.JackTransform.runJack(JackTransform.java:221)
at com.android.build.gradle.internal.transforms.JackTransform.transform(JackTransform.java:195)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:178)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:174)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 14 more
Caused by: com.android.jack.ir.JNodeInternalError: java.lang.Exception: java.lang.IllegalArgumentException: element public abstract android.app.Activity activity() is not a member of the containing type .ChildComponent nor any of its superclasses
at com.android.jack.frontend.java.JAstBuilder.handleInternalException(JAstBuilder.java:252)
at com.android.jack.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:763)
at com.android.jack.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:460)
at com.android.jack.frontend.java.JackBatchCompiler.performCompilation(JackBatchCompiler.java:223)
at com.android.jack.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1712)
at com.android.jack.frontend.java.JackBatchCompiler.compile(JackBatchCompiler.java:188)
at com.android.jack.Jack.buildSession(Jack.java:977)
at com.android.jack.Jack.run(Jack.java:496)
at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:102)
... 29 more
Caused by: java.lang.Exception: java.lang.IllegalArgumentException: element public abstract android.app.Activity activity() is not a member of the containing type .ChildComponent nor any of its superclasses
at com.android.jack.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:169)
at com.android.jack.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121)
at com.android.jack.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)
at com.android.jack.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:909)
at com.android.jack.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:434)
... 35 more
Caused by: java.lang.IllegalArgumentException: element public abstract android.app.Activity activity() is not a member of the containing type .ChildComponent nor any of its superclasses
at com.android.jack.eclipse.jdt.internal.compiler.apt.model.TypesImpl.asMemberOf(TypesImpl.java:129)
at dagger.internal.codegen.ComponentValidator.validate(ComponentValidator.java:164)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:123)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:47)
at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:329)
at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:182)
at com.android.jack.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)
... 39 more
This looks like the same Types.asMemberOf bug that has bitten eclipse users. I think this is the right bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=382590
Is there a way to check which version of ecj is being imported to jack?
I don't know the answer, but you're welcome to clone my project (linked at top), which is very simple and easy to build.
We are having the same issue. Simple TestComponent inheriting from AppComponent, using androidTestAnnotationProcessor, and we get the exact same error. Happy to help or give more info if needed.
I recommend you file a bug at https://code.google.com/p/android/issues/entry?template=Jack%20bug%20report
Awesome thanks.
Same problem here
`Error:Execution failed for task ':app:transformJackWithJackForDebugAndroidTest'.
com.android.jack.ir.JNodeInternalError: java.lang.Exception: java.lang.IllegalArgumentException: element public abstract void inject(de.company.project.base.presentation.BaseActivity) is not a member of the containing type de.projektionisten.abfahrtar.di.components.TestActivityComponent nor any of its superclasses`
Should Dagger fix that or should the Android Team fix that?
What do you suggest for quick fixing the issue in my project? I need Java 8.
Most helpful comment
I actually ran into this issue yesterday when attempting to upgrade to java 8 in android. I am using a base ActivityComponent(with Activity injector) interface that I extend from smaller components(ChildComponent) interfaces like this:
I am using the latest stable android plugin 2.2.0 and Dagger 2.7 release with the annotationProcessor notation instead of apt plugin from the android plugin.
To me it looks like a bug in the way dagger is doing validation with the jack compiler, something doesn't correctly interpret interface inheritance correctly, I also tried using component dependency from the ChildComponent and removing the extend portion and still get the same message.
Here is the stacktrace I see in gradle CLI: