kapt doesn't resolve protobuf-generated classes

Viewed 644

I get such error during the build:

e: /Users/some/path/SomeClass.java:86: error: cannot find symbol 
e:       
e:     static ConnectionType getConnectionType(Context context) { 
e:            ^ 
e:   symbol:   class ConnectionType 
e:   location: class SomeClass

Where ConnectionType is class generated by protobuf. So it looks like kapt doesn't resolve generated classes.

What I've tried?

At first I added kotlin-apt plugin:

apply plugin: 'kotlin-kapt'

Then I added brotobuf-generated classes to source set:

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
    main.java.srcDirs += 'build/generated/source/proto/main/java'
}

And also I want to have generated classes before kapt starts it's work. So I order gradle tasks this way:

afterEvaluate {
    def protoTasks = []
    tasks.each { task ->
        if (task.name.contains('proto') || task.name.contains('Proto')) {
            protoTasks.push(task)
        }
    }

    tasks.each { task ->
        if (task.name.startsWith('kapt')) {
            task.dependsOn protoTasks
        }
    }
}

But all these things don't help, I still got the same error. How to solve it?

2 Answers

No need to specify the sourceDir, if you want do so, you must specify all possible path which the Java file (maybe from Protobuf) or Kotlin file contained. In fact, the default sourceDir contains all possible paths.

Related