Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: compiler message file broken: key=compiler.err.Processor #1263

Open
AAverin opened this issue Aug 27, 2018 · 19 comments
Open

error: compiler message file broken: key=compiler.err.Processor #1263

AAverin opened this issue Aug 27, 2018 · 19 comments
Assignees

Comments

@AAverin
Copy link

AAverin commented Aug 27, 2018

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

@ronshapiro
Copy link

This is probably a Kotlin bug. Can you post a sample project?

@AAverin
Copy link
Author

AAverin commented Aug 27, 2018

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

@joshfriend
Copy link

joshfriend commented Sep 14, 2018

@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

@simpers
Copy link

simpers commented Oct 18, 2018

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.

@giem
Copy link

giem commented Jan 3, 2019

@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.

@simpers
Copy link

simpers commented Jan 4, 2019

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.

@ronshapiro
Copy link

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.

@ansman
Copy link

ansman commented Mar 13, 2019

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

@GaurangShaha
Copy link

I ran into same error, inside my project I had following situation

  • There are two component HomeComponent and CommonComponent. HomeModule and NetworkModule are created to provide the dependancies.
  • Builder of HomeComponent accepts the instance of CommonComponent.
  • Inside HomeModule I am using dependancy provided by NetworkModule.

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
    }
}

@BraisGabin
Copy link

This error is not related with Kotlin. I can reproduce it with a java only project: https://github.com/BraisGabin/daggerprocessorwrapper

@ronshapiro
Copy link

@cgdecker are you able to take a look at the latest sample project that was posted?

@cgdecker
Copy link
Member

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.

@vchernyshov
Copy link

I have solved same problem by adding missed dependency to app module.

@tbroyer
Copy link

tbroyer commented Apr 11, 2019

@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)

…and 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.

@tbroyer
Copy link

tbroyer commented Apr 11, 2019

Using @giem's sample project (#1263 (comment)), 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

@BraisGabin
Copy link

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?

@tbroyer
Copy link

tbroyer commented Apr 13, 2019

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

@BraisGabin
Copy link

🤐 Sorry, I miss read the issue.

@throughbeingjulian
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests