Kotlin 2.61
A missing @Provides annotation in Module on Dagger 2.17 results in error: compiler message file broken: key=compiler.err.Processor: org.jetbrains.kotlin.kapt3.base.ProcessorWrapper@550c0cf8 arguments={0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}
A missing @Provides annotation in Module on Dagger 2.15 results in a meaningful exception describing which dependency could not be provided
This is probably a Kotlin bug. Can you post a sample project?
I have also opened a ticket for Kotlin, but because everything works fine on 2.15 this could also be a dagger issue.
I don't have a sample project, unfortunately.
As far as I understand, this should be a matter of "forgetting" @Provides annotation in module class in any existing project to reproduce the issue
@AAverin can you please link the kotlin bug you created?
edit: sorry, nevermind, it was pretty easy to find: https://youtrack.jetbrains.com/issue/KT-26397
What's the status on this? I've been struggling for a long time getting an Instant App working and now most recently I got this error, and I'm writing it in Kotlin.
@ronshapiro I was able to reproduce the problem and have created a sample project https://github.com/giem/KaptDaggerBug
Basically the problem happens if you have a multi gradle project, and one of the gradles submodules imports something, but doesn't expose it to the parent. (like RxJava in the example project).
The kapt error occurs only if RxJava classes are used as the parameters of the methods, not when used as the return types.
Not sure if this is a dagger or kapt problem.
Basically the problem happens if you have a multi gradle project, and one of the gradles submodules imports something, but doesn't expose it to the parent. (like RxJava in the example project).
The kapt error occurs only if RxJava classes are used as the parameters of the methods, not when used as the return types.
I got the error because my base module had a dependency on Room but it was imported with implementation instead of api
implementation "androidx.room:room-runtime:$androidx_room_version"
猬囷笍
api "androidx.room:room-runtime:$androidx_room_version"
kapt "androidx.room:room-compiler:$androidx_room_version"
So if you end up hitting this error, double check the libraries you're trying to access and whether those are truly imported in the right modules or "re-exported" in submodules, depending on how you setup your gradle files.
I'm not seeing how this could be a Dagger error. Dagger only operates at the Java compiler level. If the Kotlin issue uncovers anything inside Dagger we can reopen this.
I've gotten this several times in situations like this:
class MyThing @Inject constructor() {
fun doStuff() { doPrivateStuff(SomeDependency()) }
// kapt crashes when parsing this method if SomeDependency is
// declared in a dependency included with `implementation`
private fun doStuff(someDependency: SomeDependency) {}
}
In those situations you can easily mark the offending functions as @JvmSynthetic
I ran into same error, inside my project I had following situation
I had not written a function signature returning the dependency inside HomeComponent. Which is causing this issue. After adding a method signature everything works normally.
@Component(modules = [NetworkModule::class])
interface CommonComponent {
fun provideRetrofit(): Retrofit //Added this method to resolve the issue
}
@Component(
modules = [HomeFragmentModule::class, ViewModelFactoryModule::class],
dependencies = [CommonComponent::class]
)
interface HomeFragmentComponent : BaseFragmentComponent<HomeFragment> {
@Component.Builder
interface Builder {
fun commonComponent(component: CommonComponent): Builder
fun build(): HomeFragmentComponent
}
}
@Module
class NetworkModule {
@Provides
fun provideOkHttpClient(interceptor: HttpLoggingInterceptor): OkHttpClient =
OkHttpClient.Builder().addInterceptor(interceptor).build()
@Provides
fun provideLoggingInterceptor(): HttpLoggingInterceptor =
HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.NONE
}
}
@Provides
fun provideCallAdapterFactory(): CoroutineCallAdapterFactory = CoroutineCallAdapterFactory()
@Provides
fun provideGson(): Gson = Gson()
@Provides
fun provideGsonConverterFactory(gson: Gson): GsonConverterFactory =
GsonConverterFactory.create(gson)
@Provides
fun provideRetrofit(
client: OkHttpClient,
gsonConverterFactory: GsonConverterFactory,
coroutineCallAdapterFactory: CoroutineCallAdapterFactory
): Retrofit {
return Retrofit.Builder()
.baseUrl("")
.addConverterFactory(gsonConverterFactory)
.client(client)
.addCallAdapterFactory(coroutineCallAdapterFactory)
.build()
}
}
@Module(includes = [BindingModule::class])
class HomeFragmentModule {
@Provides
fun provideRetrofitHomeService(retrofit: Retrofit): DummyService {
return retrofit.create(DummyService::class.java)
}
@Module
interface BindingModule {
@Binds
@IntoMap
@ViewModelKey(HomeViewModel::class)
fun bindHomeViewModel(viewModel: HomeViewModel): ViewModel
}
}
This error is not related with Kotlin. I can reproduce it with a java only project: https://github.com/BraisGabin/daggerprocessorwrapper
@cgdecker are you able to take a look at the latest sample project that was posted?
Perhaps the issue is related to Gradle? I tried a similar setup to that sample project with just Maven modules (and nothing Android-related) and didn't run into any issue.
I have solved same problem by adding missed dependency to app module.
@BraisGabin I can't reproduce the error on your project, either on the last commit, or the previous one in Kotlin.
With Java 8 I always get (task will be :modulea:kaptDebugKotlin in the second-to-last commit):
> Task :modulea:compileDebugJavaWithJavac FAILED
error: cannot access ComponentC
class file for com.braisgabin.dagger.modulec.ComponentC not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.braisgabin.dagger.modulec.ComponentC not found
1 error
which is expected as modulec is not visible to modulea (declared as implementation in moduleb, so not present in the compile classpath of modulea, only its runtime classpath)
鈥nd strangely with Java 11 it compiles without error (that's a bug in Gradle or the Android Gradle Plugin, it should fail).
./gradlew --version gives me (with Java 8):
Gradle 4.10.1
------------------------------------------------------------
Build time: 2018-09-12 11:33:27 UTC
Revision: 76c9179ea9bddc32810f9125ad97c3315c544919
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_212 (Oracle Corporation 25.212-b01)
OS: Linux 5.0.7-arch1-1-ARCH amd64
Might be related to you JDK flavor and/or version.
Using @giem's sample project (https://github.com/google/dagger/issues/1263#issuecomment-451044639), my output is:
w: /home/tbr/Projects/KaptDaggerBug/model/src/main/java/com/example/model/Model.kt: (13, 16): Parameter 'flowable' is never used
e: error: cannot access Flowable
class file for io.reactivex.Flowable not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for io.reactivex.Flowable not found
so bug very likely is related to the JDK flavor/version.
./gradlew --version
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_212 (Oracle Corporation 25.212-b01)
OS: Linux 5.0.7-arch1-1-ARCH amd64
Ok, to ensure that the tests are reproducible I configured travis in my test project. The results I get:
> Task :modulea:compileDebugJavaWithJavac FAILED
error: cannot access ComponentC
class file for com.braisgabin.dagger.modulec.ComponentC not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.braisgabin.dagger.modulec.ComponentC not found
1 error
> Task :modulea:kaptDebugKotlin FAILED
e: error: cannot access ComponentC
class file for com.braisgabin.dagger.modulec.ComponentC not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.braisgabin.dagger.modulec.ComponentC not found
> Task :modulec:compileDebugJavaWithJavac
/home/travis/build/BraisGabin/daggerprocessorwrapper/modulec/build/generated/source/kapt/debug/com/braisgabin/dagger/modulec/DaggerComponentC.java:4: error: package javax.annotation.processing does not exist
import javax.annotation.processing.Generated;
^
/home/travis/build/BraisGabin/daggerprocessorwrapper/modulec/build/generated/source/kapt/debug/com/braisgabin/dagger/modulec/DaggerComponentC.java:6: error: cannot find symbol
@Generated(
^
symbol: class Generated
2 errors
So as far as I can understand this error is related with the JDK8. So, if we move to JDK11 it'll work. The problem is that if we need to use katp we can not move to JDK11 because of #1449. Am I right? Am I loosing something?
Is this a "wont fix" or should we support JDK8?
Wait a minute: this issue is about the error message only, which you didn't reproduce.
The failure you're seeing is tracked at #970
馃 Sorry, I miss read the issue.
I had the same issue with a multi-module project I was working on last week. Turns out I was injecting an object with a transitive dependency from another module. Adding the dependency directly into the module not compiling solved my issue.
Most helpful comment
What's the status on this? I've been struggling for a long time getting an Instant App working and now most recently I got this error, and I'm writing it in Kotlin.