Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kapt doesn't resolve protobuf-generated classes

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?

like image 655
VasyaFromRussia Avatar asked Jul 20 '17 13:07

VasyaFromRussia


1 Answers

The error was caused by wrong path to protobuf source set. I had to use correct flavor name in it, like:

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

instead of

sourceSets {
    // ...
    main.java.srcDirs += 'build/generated/source/proto/main/java'
}
like image 190
VasyaFromRussia Avatar answered Nov 03 '22 07:11

VasyaFromRussia