question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IllegalArgumentException with TestComponent extends ApplicationComponent

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

3reactions
sirivanleocommented, Sep 23, 2016

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
0reactions
unlimited101commented, Nov 18, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger 2 injection in Android instrumentation tests
It works perfectly fine for Classes/Activities/Fragments in the main application component, but my test component seems to be missing some ...
Read more >
Diff - platform/cts - Google Git
-public class AudioFrequencyLineActivity extends PassFailButtons. ... fail("Expected IllegalArgumentException when serializing an empty report"); ...
Read more >
Fancy Fragment = FragmentFactory+Dagger | by MJ Studio
We extended FragmentFactoy class and overrided instantiate method. It's time to inject our first FragmentFactory with Dagger.
Read more >
Binder.java - Android Code Search
application component (a {@link android.app. ... that extend this Binder class and that are not static. These kind ... throw new IllegalArgumentException();. }....
Read more >
Java Examples for org.restlet.Component - Javatips.net
This java examples will help you to understand the usage of org.restlet.Component. These source code samples are taken from different open source projects....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found