在 AWS API 和 Android 的 Appsync 服务中重复 类

Duplicate Classes in AWS API and Appsync Serivces for Android

我在 android 应用程序中收到 AWS API 和 AWS Appsync 服务的重复 class 错误。我曾尝试降级版本,但这会导致其他文件出现错误。我已经尝试了 post 中的解决方案:Android Studio: Resolving Duplicate Classes。 None 这些似乎有效,因为它们只会导致更多错误或没有任何变化。

这是错误:

> Task :app:checkDebugDuplicateClasses FAILED
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.amplifyframework.api.aws.AuthorizationType found in modules aws-api-1.4.0-runtime (com.amplifyframework:aws-api:1.4.0) and aws-api-appsync-1.25.1-runtime (com.amplifyframework:aws-api-appsync:1.25.1)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

这是 build.gradle 文件:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'

}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.wcsng.dlocapp"
        minSdkVersion 26
        targetSdkVersion 30
        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
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true


    }
    dataBinding {
        enabled true
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    //implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
    //implementation 'com.jjoe64:graphview:4.2.2'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.amplifyframework:core:1.25.1'
    implementation 'com.amplifyframework:aws-api:1.4.0'
    implementation 'com.amplifyframework:aws-auth-cognito:1.4.0'
    implementation 'com.amplifyframework:aws-datastore:1.25.1'
}

如果您需要更多文件来解决此问题,请告诉我。感谢任何帮助。

如果您想从 Android 应用程序调用 AWS 服务,那么我建议查看新的 AWS SDK for Kotlin.这还是一个新的API;但是,还有一个 example that shows you how to invoke AWS Services,例如 Amazon DynamoDB。

至于重复的库,我在指定 sns 依赖项时也看到了。为消除该问题,Gradle 构建文件设置为:

  api("aws.sdk.kotlin:sns:0.4.0-alpha")  {
     exclude group: "xmlpull", module: "xmlpull"
   }