Search code examples
androidamazon-web-servicesandroid-studioaws-amplify

Duplicate Classes in AWS API and Appsync Serivces for Android


I am getting a duplicate class error for AWS API and AWS Appsync services in my android app. I have tried downgrading the versions but that causes bugs in other files. I have tried the solutions in this post: Android Studio: Resolving Duplicate Classes. None of these seem to work as they only cause more bugs or no changes.

Here is the error:

> 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.

Here is the build.gradle file:

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'
}

Let me know if you need more files to solve this. Any help is appreciated.


Solution

  • if you want to invoke AWS Services from an Android app, then I suggest looking at the new AWS SDK for Kotlin. This is still a new API; however, there is an example that shows you how to invoke AWS Services such as Amazon DynamoDB.

    As far as duplicate libs, I saw that too when i specified the sns dependencies. To eliminate that issue, the Gradle build file was set to:

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