简体   繁体   中英

Assemble error while using latest gRPC plugin on Android -> Input is shadowed in the --proto_path (Gradle 7.0.1)

I am trying to update an Android project to use the latest gradle plugin (7.0.1), from the current 3.6.4 that it is using. In order to do this, considering the project is using protobuf, I need to update the protobuf and gRPC dependencies, as the current ones are not compatible with the latest plugin.

I have followed https://github.com/grpc/grpc-java in order to use the latest dependency versions. I updated the dependencies to the following versions:

implementation 'io.grpc:grpc-okhttp:1.40.1'
implementation 'io.grpc:grpc-protobuf-lite:1.40.1'
implementation 'io.grpc:grpc-stub:1.40.1'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
protobuf "com.google.protobuf:protobuf-java:3.17.3"

I am using the latest protobuf plugin

plugins {
    id 'com.google.protobuf' version '0.8.17'
}

And use the following block for code-gen

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:3.17.3"
  }
  plugins {
    grpc {
      artifact = "io.grpc:protoc-gen-grpc-java:1.40.1"
    }
  }
  generateProtoTasks {
    all().each { task ->
      task.builtins {
        java { option 'lite' }
      }
      task.plugins {
        grpc { option 'lite' }
      }
    }
  }
}

The gradle sync succeeds while using those, the problem is when I try to assemble the project, I get the following error:

Execution failed for task ':App:generateDebugProto'. protoc: stdout: . stderr: C:\\Users\\phantom\\AndroidStudioProjects\\Protobuf\\App\\build\\extracted-protos\\main\\google\\protobuf\\any.proto: Input is shadowed in the --proto_path by "C:/Users/phantom/AndroidStudioProjects/Protobuf/App/build/extracted-include-protos/debug/google/protobuf/any.proto". Either use the latter file as your input or reorder the --proto_path so that the former file's location comes first.

From what I understand while reading the error, the problem is that the proto files are generated now in both extracted-protos and extracted-include-protos build files, and the latter shadows the first one. I have checked, in the previous version, the files were generated solely in the extracted-protos build files. Is there a way to skip generating the files in the extracted-include-protos ? Or what would be the course of action to be able to assemble the project?

I ran into this same issue yesterday. This is more of a workaround than a full answer. It got me working with Google speech-to-text, but it doesn't work if you add in a non-beta version of text-to-speech, so if anybody has a better answer please post.

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.17.3'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:1.40.1"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                // In most cases you don't need the full Java output
                // if you use the lite output.
                remove java
            }
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

implementation 'io.grpc:grpc-okhttp:1.40.1'
implementation 'io.grpc:grpc-protobuf-lite:1.25.0'
implementation 'io.grpc:grpc-stub:1.40.1'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
protobuf "com.google.protobuf:protobuf-java:3.17.3"

implementation("com.google.cloud:google-cloud-speech:1.22.1") {
    exclude group: 'com.google.protobuf', module: 'protobuf-java'
    exclude group: 'com.google.api.grpc'
}

Note the versions of grpc-protobuf-lite and google-cloud-speech. I had to downgrade both of them from the latest.

Had the same issue, After trying every possible gradle configuration for 2 days. I just manually deleted all the proto files under ../build/extracted-include-protos/debug/google/protobuf/ and the error is gone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM