aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.03k stars 549 forks source link

Using AWS Android SDK with Room library #1196

Closed LiMuBei closed 4 years ago

LiMuBei commented 5 years ago

State your question I'm trying to use AWS Android SDK together with the Room library for local data persistence in my app. In the lintDebug task I am getting an error (see below) because of version conflicts with the gson library. Is this somehow fixable? Are these libraries incompatible in these versions?

Which AWS Services are you utilizing? Cognito User Pools

Provide code snippets (if applicable)

Environment(please complete the following information):

Error message I get:

Could not determine the dependencies of task ':app:lintDebug'.
> Could not resolve all artifacts for configuration ':app:debugAndroidTestRuntimeClasspath'.
   > Could not resolve com.google.code.gson:gson:{strictly 2.2.4}.
     Required by:
         project :app
      > Cannot find a version of 'com.google.code.gson:gson' that satisfies the version constraints: 
           Dependency path 'One Rep Ahead:app:unspecified' --> 'androidx.room:room-testing:2.1.0' --> 'androidx.room:room-migration:2.1.0' --> 'com.google.code.gson:gson:2.8.0'
           Constraint path 'One Rep Ahead:app:unspecified' --> 'com.google.code.gson:gson:{strictly 2.2.4}' because of the following reason: debugRuntimeClasspath uses version 2.2.4
           Dependency path 'One Rep Ahead:app:unspecified' --> 'com.amazonaws:aws-android-sdk-mobile-client:2.15.2' --> 'com.amazonaws:aws-android-sdk-auth-core:2.15.2' --> 'com.amazonaws:aws-android-sdk-core:2.15.2' --> 'com.google.code.gson:gson:2.2.4'

   > Could not resolve com.google.code.gson:gson:2.8.0.
     Required by:
         project :app > androidx.room:room-testing:2.1.0 > androidx.room:room-migration:2.1.0
      > Cannot find a version of 'com.google.code.gson:gson' that satisfies the version constraints: 
           Dependency path 'One Rep Ahead:app:unspecified' --> 'androidx.room:room-testing:2.1.0' --> 'androidx.room:room-migration:2.1.0' --> 'com.google.code.gson:gson:2.8.0'
           Constraint path 'One Rep Ahead:app:unspecified' --> 'com.google.code.gson:gson:{strictly 2.2.4}' because of the following reason: debugRuntimeClasspath uses version 2.2.4
           Dependency path 'One Rep Ahead:app:unspecified' --> 'com.amazonaws:aws-android-sdk-mobile-client:2.15.2' --> 'com.amazonaws:aws-android-sdk-auth-core:2.15.2' --> 'com.amazonaws:aws-android-sdk-core:2.15.2' --> 'com.google.code.gson:gson:2.2.4'

   > Could not resolve com.google.code.gson:gson:2.2.4.
     Required by:
         project :app > com.amazonaws:aws-android-sdk-core:2.15.2
      > Cannot find a version of 'com.google.code.gson:gson' that satisfies the version constraints: 
           Dependency path 'One Rep Ahead:app:unspecified' --> 'androidx.room:room-testing:2.1.0' --> 'androidx.room:room-migration:2.1.0' --> 'com.google.code.gson:gson:2.8.0'
           Constraint path 'One Rep Ahead:app:unspecified' --> 'com.google.code.gson:gson:{strictly 2.2.4}' because of the following reason: debugRuntimeClasspath uses version 2.2.4
           Dependency path 'One Rep Ahead:app:unspecified' --> 'com.amazonaws:aws-android-sdk-mobile-client:2.15.2' --> 'com.amazonaws:aws-android-sdk-auth-core:2.15.2' --> 'com.amazonaws:aws-android-sdk-core:2.15.2' --> 'com.google.code.gson:gson:2.2.4'
desokroshan commented 5 years ago

@LiMuBei Thanks for reaching out. Can you share more information about the Room library you are trying to use such as its version etc.?

LiMuBei commented 5 years ago

@desokroshan Sure! Here are the dependencies in my build.gradle:

dependencies {
    // Room components
    implementation "androidx.room:room-runtime:$rootProject.room"
    implementation "androidx.room:room-ktx:$rootProject.room"
    kapt "androidx.room:room-compiler:$rootProject.room"
    androidTestImplementation "androidx.room:room-testing:$rootProject.room"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.15.2'
    implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.15.2'
    implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.15.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
    implementation "androidx.room:room-ktx:$rootProject.room"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    // Coroutines
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"
}

Where the Room version is defined as room = '2.1.0'

LiMuBei commented 5 years ago

I'm basically following this codelab: https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/

mutablealligator commented 4 years ago

@LiMuBei Thank you for reporting to us. The aws-android-sdk-core depends on gson library for serialization and deserialization. One possible workaround you could do it to exclude the gson library version that we depend on in your build.gradle and declare a version of gson that would work for you.

We have not tested or upgraded our gson version beyond the current version we support 2.2.4. I would recommend you to try this as an experiment.

stale[bot] commented 4 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

LiMuBei commented 4 years ago

So I was able to resolve this, by manually adding the missing Gson dependency for Room.