构建时Android数据存储protobuf冲突

问题描述 投票:0回答:1

我正在尝试在 Android 上使用 protobuf 数据存储,但遇到构建问题。以下是错误:

Duplicate class com.google.protobuf.Field$Kind$KindVerifier found in modules jetified-protobuf-javalite-3.21.11 (com.google.protobuf:protobuf-javalite:3.21.11) and jetified-protobuf-kotlin-4.26.0 (com.google.protobuf:protobuf-kotlin:4.26.0)

Duplicate class com.google.protobuf.FieldKt found in modules jetified-protobuf-kotlin-4.26.0 (com.google.protobuf:protobuf-kotlin:4.26.0) and jetified-protobuf-kotlin-lite-3.21.11 (com.google.protobuf:protobuf-kotlin-lite:3.21.11)

这只是日志的一部分,但是有大量的行重复

Duplicate class

下面是我的gradle:

plugins {
    id 'kotlinx-serialization'
    id "com.google.protobuf" version "0.8.17"
}

dependencies {

implementation "androidx.datastore:datastore:1.1.0"
    implementation "com.google.protobuf:protobuf-javalite:3.19.4"
    implementation "com.google.protobuf:protobuf-kotlin-lite:3.21.11"
}

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

    // 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'
                }
                kotlin {
                    option 'lite'
                }
            }
        }
    }
}

有什么想法吗?

我尝试了多次版本更改,但没有任何改变

android kotlin sharedpreferences datastore
1个回答
0
投票

试试这个:

plugins{

 id "com.google.protobuf" version "0.9.1"

}
dependencies {

    //just use javalite dependency.
    implementation("androidx.datastore:datastore:1.0.0")
    implementation("com.google.protobuf:protobuf-javalite:4.26.0-RC2")

}
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.25.2'
    }
    plugins {
        javalite {
            artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
            task.plugins { 
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.