Gradle找不到com.google.protobuf。

4

我正在尝试使用gradle编译protobuf项目。但是,在protobuf生成的Java文件中,我遇到了以下错误:

enter image description here

这是build.gradle文件:

    // Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'


// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.protobuf:protobuf-java:3.5.1'
    implementation 'com.google.protobuf:protobuf-gradle-plugin:0.8.7'
    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}

有什么遗漏的提示吗?

2
我认为 protobuf-gradle-plugin 不应该成为你的应用程序依赖的一部分。相反,它是一个放在顶层 gradle 文件的 gradle 插件,你需要应用它。 - undefined
1个回答

0
对我来说,将这行代码更新为与另一行代码相同的版本号解决了问题。
dependencies {
    implementation  "androidx.datastore:datastore:1.0.0"
    implementation  "com.google.protobuf:protobuf-javalite:3.18.0"
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.18.0"
    }

    // Generates the java Protobuf-lite code for the Protobufs in this project. See
    // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
    // for more information.
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接