Open mnayef95 opened 5 years ago
Same on dagger 2.16
Related issue: https://issuetracker.google.com/issues/133461087
I get the same error on 2.24 too.
Same error since moved to Android Studio 3.5, it's only triggered while running tests from inside the IDE. Console is fine.
I encountered the same error after migrating to Android Studio 3.5 for 2.24 version
. It seems to be because of changes in kapt
.
Same issue here using dagger 2.11.
Same issue here using dagger 2.19.
avoiding any usages of @set:Inject
can be used as a workaround
avoiding any usages of
@set:Inject
can be used as a workaround
I don't have any @set:Inject, other suggestions?
For me this did not work:
@set:Inject
lateinit var something: Something
This did not work either:
var something: Something? = null
@Inject set
But, this did:
var something: Something? = null
@Inject set(value) {
field = value
}
IDE will complain that the full declaration is redundant and can be simplified, however this was the only way that kapt
accepted :)
@TheMedo thanks! It works.
It seems that before the update @Inject set
was shorthand for field = value
but this magic is now removed (more explicit).
You can also use:
@Inject
@JvmField
var something: Something? = null
Thanks to @mennovogel
For what it's worth I was able to get it to compile if i downgrade from gradle plugin 3.5.0 to 3.4.2 as a temporary developer fix to unblock while we try the above
@JvmField
change
Seems that i have managed it to work on: android studio 3.5.0 dagger version 2.24, gradle plugin 2.5.0 wrapper 5.4.1 Just double check that your project neither use @set:Inject or @Inject set structures.
@Inject lateinit var: Some
would be enough
Seems that i have managed it to work on: android studio 3.5.0 dagger version 2.24, gradle plugin 2.5.0 wrapper 5.4.1
Just double check that your project neither use @set:Inject or @Inject set structures.
@Inject lateinit var: Some
would be enough
I get the same error on 2.24 too.
However, I was able to build after changing the SDK location AdoptOpenJDK 8 or Amazon Corretto 8.
/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.0_222, x86_64: "Amazon Corretto 8" /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
1.8.0_222, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
I got exactly the same issue after Android Studio was updated to the version 3.5 I fixed this issue in 4 steps:
Added kotlinOptions section with jvmTarget into app/build.gradle
kotlinOptions { jvmTarget = "1.8" }
(the section compileOptions is already there)
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
Upgraded dagger from 2.22.1 to 2.24
Disabled incremental kapt in gradle.properties
kapt.incremental.apt=false
Invalidated build cache, restarted Android Studio and rebuilt the project
Note, that the CI build is working all the time.
I got exactly the same issue after Android Studio was updated to the version 3.5 I fixed this issue in 4 steps:
- Added kotlinOptions section with jvmTarget into app/build.gradle
kotlinOptions { jvmTarget = "1.8" }
(the section compileOptions is already there)compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
- Upgraded dagger from 2.22.1 to 2.24
- Disabled incremental kapt in gradle.properties
kapt.incremental.apt=false
- Invalidated build cache, restarted Android Studio and rebuilt the project
Note, that the CI build is working all the time.
Didn't help in my case :(
Edited out because this is a different issue
Have you seen this article? https://www.donnfelker.com/dagger-open-jdk-version-mismatch/
When changing the jdk location in the module settings to what I'm running Android Studio with I no longer get this problem.
My jdk location: /usr/lib/jvm/java-1.8.0-openjdk
This links to my current jdk which is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.fc31.x86_64 as seen below:
$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Hit this again today: JDK 11.0.8 Kotlin 1.4.10 Dagger 2.28.3
@Singleton
class FooClass @Inject constructor(
thingProvider: ThingProvider
) : FooTracker(thingProvider) {
var myVar: Boolean = false
.....
}
Which produces bytecode like:
// access flags 0x11
public final setMyVar(Z)V
// annotable parameter count: 1 (visible)
// annotable parameter count: 1 (invisible)
L0
LINENUMBER 13 L0
ALOAD 0
ILOAD 1
PUTFIELD com/example/FooClass.myVar : Z
RETURN
L1
LOCALVARIABLE this Lcom/example/FooClass; L0 L1 0
LOCALVARIABLE <set-?> Z L0 L1 1
MAXSTACK = 2
MAXLOCALS = 2
Looks like <set-?>
is a local variable name?
and we get this exception...
Caused by: com.sun.tools.javac.processing.AnnotationProcessingError: java.lang.IllegalArgumentException: not a valid name: <set-?>Provider
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:992)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:896)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1222)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1334)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1157)
... 38 more
Caused by: java.lang.IllegalArgumentException: not a valid name: <set-?>Provider
at com.squareup.javapoet.Util.checkArgument(Util.java:53)
at com.squareup.javapoet.FieldSpec.builder(FieldSpec.java:91)
at dagger.internal.codegen.writing.MembersInjectorGenerator.write(MembersInjectorGenerator.java:177)
at dagger.internal.codegen.writing.MembersInjectorGenerator.write(MembersInjectorGenerator.java:73)
at dagger.internal.codegen.base.SourceFileGenerator.generate(SourceFileGenerator.java:77)
at dagger.internal.codegen.validation.InjectBindingRegistryImpl$BindingsCollection.generateBindings(InjectBindingRegistryImpl.java:97)
at dagger.internal.codegen.validation.InjectBindingRegistryImpl.generateSourcesForRequiredBindings(InjectBindingRegistryImpl.java:191)
at dagger.internal.codegen.ComponentProcessor.postRound(ComponentProcessor.java:198)
at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:183)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:161)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:980)
... 43 more
I've figured this one out - this only happens when Dagger attempts to generate a MembersInjector
for a class not in the current compilation unit. You need to ensure you're running dagger-compiler
over every project that has injections. Otherwise, Dagger will try to generate it later in a downstream subproject. Aside from potentially hitting this issue (I suspect the problem is the elements API does not expose the setter correctly in this case), you will also break incremental processing in kapt.
If we run dagger-compiler
over all the target classes in their own modules we don't have this issue.
I've figured this one out - this only happens when Dagger attempts to generate a
MembersInjector
for a class not in the current compilation unit. You need to ensure you're runningdagger-compiler
over every project that has injections. Otherwise, Dagger will try to generate it later in a downstream subproject. Aside from potentially hitting this issue (I suspect the problem is the elements API does not expose the setter correctly in this case), you will also break incremental processing in kapt.If we run
dagger-compiler
over all the target classes in their own modules we don't have this issue.
what worked for me is changing the JDK. I changed to this JDK https://adoptopenjdk.net/?variant=openjdk8&jvmVariant-hotspot
In my case @JvmOverloads with Kotlin's default parameter value causes this bug. Old, Java-way methods overloading is my solution.
Hi all, i'm facing issue with dagger after updating android studio to 3.5, this is the stacktrace
Dagger version: 2.24