java - androidx.security 依赖问题

标签 java android androidx android-jetpack

我需要加密我的 SharedPreferences,所以我决定尝试使用:

实现“androidx.security:security-crypto:1.0.0-rc01”

它至少需要 23 的 Sdk,因此我更改了我的应用程序以与其兼容。

现在我得到了一堆红线,如下所示:

Duplicate class com.google.protobuf.Timestamp$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Timestamp$Builder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.TimestampOrBuilder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.TimestampProto found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Type found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Type$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Type$Builder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.TypeOrBuilder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.TypeProto found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt32Value found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt32Value$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt32Value$Builder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt32ValueOrBuilder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt64Value found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt64Value$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt64Value$Builder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UInt64ValueOrBuilder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.UninitializedMessageException found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.UnknownFieldSetLite found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.UnmodifiableLazyStringList found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.UnmodifiableLazyStringList$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.UnmodifiableLazyStringList$2 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.UnsafeUtil found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.UnsafeUtil$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Utf8 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Utf8$Processor found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Utf8$SafeProcessor found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Utf8$UnpairedSurrogateException found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Utf8$UnsafeProcessor found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Value found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Value$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Value$Builder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.Value$KindCase found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.ValueOrBuilder found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.protobuf.WireFormat found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$FieldType found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$FieldType$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$FieldType$2 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$FieldType$3 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$FieldType$4 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$JavaType found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$Utf8Validation found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$Utf8Validation$1 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$Utf8Validation$2 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WireFormat$Utf8Validation$3 found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.WrappersProto found in modules jetified-protobuf-javalite-3.11.1.jar (com.google.protobuf:protobuf-javalite:3.11.1) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)

Go to the documentation to learn how to Fix dependency resolution errors.

我的 build.gradle 如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:19.3.1'
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.firebase:firebase-analytics:17.4.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-firestore:21.4.3'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.material:material:1.2.0-alpha06'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.ms-square:expandableTextView:0.1.4'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.google.firebase:firebase-functions:19.0.2'
    implementation 'com.google.firebase:firebase-messaging:20.1.6'
    implementation 'com.google.firebase:firebase-core:17.4.0'
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'androidx.security:security-crypto:1.0.0-rc01'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply plugin: 'com.google.gms.google-services'
repositories {
    mavenCentral()
}

如何解决这个问题?

谢谢

最佳答案

这取决于 com.google.crypto.tink:tink-android:1.3.0,它会引入 protobuf-javalite:

implementation ("androidx.security:security-crypto:1.0.0-rc01") {
    exclude group: "com.google.protobuf", module: "protobuf-javalite"
}

关于java - androidx.security 依赖问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61503981/

相关文章:

java - Java 中引用属性的问题

java - 当我使用 Wea​​kReference 时,无法解析 android 上的符号消息

android layout-land 和 screen-rotation 处理

android - 编译ARM二进制文件,在ARMulator中运行它们

android - FragmentManager 和 androidx FragmentManager

java - 我想通过比较两天来打印 31 个工作日。它应该以有效格式打印日期

java - JPQL 类似表达式需要 int 值

android - 如何在 RTL 布局中直接在图像上使用 "autoMirrored"属性

android - 将 Cordova Android 项目迁移到 AndroidX

java - 迁移到 AndroidX - ResultReceiver 在哪里