aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
231 stars 108 forks source link

Running the app with amplify SDK V2.14.13 on Android OS version 7 and 7.1 devices immediately crashes. #2790

Closed cojobs closed 1 month ago

cojobs commented 1 month ago

Before opening, please confirm:

Language and Async Model

Kotlin, Kotlin - Coroutines

Amplify Categories

Analytics

Gradle script dependencies

```groovy api ("com.amplifyframework:aws-analytics-pinpoint:2.14.13") { exclude( group = "androidx.lifecycle", module = "lifecycle-viewmodel-ktx") } api ("com.amplifyframework:aws-auth-cognito:2.14.13") { exclude( group = "androidx.lifecycle", module = "lifecycle-viewmodel-ktx") } ```

Environment information

``` Build time: 2023-04-21 12:31:26 UTC Revision: 1cf537a851c635c364a4214885f8b9798051175b Kotlin: 1.8.10 Groovy: 3.0.15 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 17.0.10 (JetBrains s.r.o. 17.0.10+0-17.0.10b1087.21-11572160) OS: Mac OS X 12.3 aarch64 ```

Please include any relevant guides or documentation you're referencing

https://docs.amplify.aws/android/start/project-setup/prerequisites/

Describe the bug

Running the app with amplify SDK V2.14.13 on Android OS version 7 and 7.1 devices immediately crashes.

The documentation https://docs.amplify.aws/android/start/project-setup/prerequisites/ specifies android 7.0 or later.

Does the amplify SDK only support Android 8.0 and above, contrary to what the guide documentation says? If not, could you please revise it to support from android 7.0 onwards?

(https://developer.android.com/reference/java/time/Duration says that the Duration class was added as of API level 26.)

Reproduction steps (if applicable)

  1. Run the app with the amplify SDK V2.14.13 on top of an android 7.0 or 7.1 device.
  2. It crashes immediately.

Code Snippet

Amplify.addPlugin(AWSCognitoAuthPlugin())

Log output

``` java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Duration; at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineKt.buildClient(OkHttpEngine.kt:88) at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineKt.access$buildClient(OkHttpEngine.kt:1) at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine.(OkHttpEngine.kt:44) at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine$Companion.invoke(OkHttpEngine.kt:38) at aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngineJVMKt.newDefaultHttpEngine(DefaultHttpEngineJVM.kt:14) at aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngineKt.DefaultHttpEngine(DefaultHttpEngine.kt:23) at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineConstructor$1.invoke(HttpEngineConfigImpl.kt:20) at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineConstructor$1.invoke(HttpEngineConfigImpl.kt:20) at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineSupplier$1.invoke(HttpEngineConfigImpl.kt:21) at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineSupplier$1.invoke(HttpEngineConfigImpl.kt:21) at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl.buildHttpEngineConfig(HttpEngineConfigImpl.kt:75) at aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient$Config$Builder.buildHttpEngineConfig(CognitoIdentityClient.kt) at aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient$Config.(CognitoIdentityClient.kt:133) at aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient$Config.(CognitoIdentityClient.kt) at aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient$Config$Builder.build(CognitoIdentityClient.kt:284) at aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient$Config$Builder.build(CognitoIdentityClient.kt:171) at aws.smithy.kotlin.runtime.client.AbstractSdkClientBuilder.build(AbstractSdkClientBuilder.kt:20) at aws.smithy.kotlin.runtime.client.AbstractSdkClientBuilder.build(AbstractSdkClientBuilder.kt:13) at aws.smithy.kotlin.runtime.client.SdkClientFactory$DefaultImpls.invoke(SdkClientFactory.kt:32) at aws.sdk.kotlin.runtime.config.AbstractAwsSdkClientFactory.invoke(AbstractAwsSdkClientFactory.kt:42) at com.amplifyframework.auth.cognito.AWSCognitoAuthService$Companion.fromConfiguration$aws_auth_cognito_release(AWSCognitoAuthService.kt:53) at com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin.configure(AWSCognitoAuthPlugin.kt:133) at com.amplifyframework.core.category.Category.configure(Category.java:92) at com.amplifyframework.core.Amplify.configure(Amplify.java:159) at com.amplifyframework.core.Amplify.configure(Amplify.java:129) Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Duration" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.xxx.xxx.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx.debug-1/lib/arm64, /data/app/com.xxx.xxx.debug-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:380) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 47 more ```

amplifyconfiguration.json

No response

GraphQL Schema

```graphql // Put your schema below this line ```

Additional information and screenshots

No response

mattcreaser commented 1 month ago

Hi @cojobs. Amplify (and its dependencies) use Java 8 features, so if your minimum SDK is below 26 you need to enable core library desugaring for your app. This is covered in the install Amplify libraries section of the docs.

Here's an example:

// build.gradle.kts
android {
    compileOptions {
        isCoreLibraryDesugaringEnabled = true
    }
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
}

This should resolve your issue. Please let us know if you have any other questions.

cojobs commented 1 month ago

Thanks for the detailed answer, I'll give it a try!

mattcreaser commented 1 month ago

Great. I'll close this issue but please feel free to open a new one if necessary.

github-actions[bot] commented 1 month ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.