amplify-android: "Failed to instantiate AWSMobileClient within 10 seconds" in Application.onCreate()
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
Language and Async Model
Kotlin
Amplify Categories
Authentication, REST API
Gradle script dependencies
def amplify_version = '1.31.1'
implementation "com.amplifyframework:core:$amplify_version"
implementation "com.amplifyframework:aws-auth-cognito:$amplify_version"
implementation "com.amplifyframework:aws-api:$amplify_version"
Environment information
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time: 2022-03-31 15:25:29 UTC
Revision: 540473b8118064efcc264694cbcaa4b677f61041
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 1.8.0_322 (Temurin 25.322-b06)
OS: Mac OS X 10.16 x86_64
Please include any relevant guides or documentation you’re referencing
No response
Describe the bug
In Firebase we see a concerning amount of crashes caused by:
java.lang.RuntimeException: Unable to create application {insert app package}.CustomApplication: AuthException{message=Failed to instantiate AWSMobileClient within 10 seconds, cause=null, recoverySuggestion=Check network connectivity}
According to the Firebase crash report 100% of the issues are happening while the app is in the background. The last 90 days we have had 1512 occurrences, which considering our current user base is an alarming amount. We cannot use a try catch as we need the Amplify SDK in order to make critical API calls (so the only way to recover would be to close the app). This crash has been around since our initial introduction of Amplify SDK.
Reproduction steps (if applicable)
Cannot reproduce it. Tried it opening the app with Wi-Fi and data turned off but this will not cause a crash. This crash also doesn’t happen for all users.
Code Snippet
Relevant code from CustomApplication, Dagger is used for injection.
@Inject
lateinit var amplifyConfig: AmplifyConfiguration
private fun initAmplify() {
authSessionHubSubscriber.subscribe()
Amplify.addPlugin(AWSCognitoAuthPlugin())
val apiPlugin: AWSApiPlugin = AWSApiPlugin.builder()
.configureClient(AMPLIFY_API_NAME) { clientBuilder ->
clientBuilder.addInterceptor(HttpLoggingInterceptor().apply { level = BASIC })
clientBuilder.addInterceptor(chuckerInterceptor)
clientBuilder.connectTimeout(AMPLIFY_TIMEOUT_SECONDS, SECONDS)
clientBuilder.writeTimeout(AMPLIFY_TIMEOUT_SECONDS, SECONDS)
clientBuilder.readTimeout(AMPLIFY_TIMEOUT_SECONDS, SECONDS)
}
.build()
Amplify.addPlugin(apiPlugin)
Amplify.configure(amplifyConfig, applicationContext)
}
companion object {
private const val AMPLIFY_API_NAME = "***********"
private const val AMPLIFY_TIMEOUT_SECONDS = 20L
}
// Provide function for the amplifyConfig
@Provides
fun provideAmplifyConfig(context: Context): AmplifyConfiguration {
return AmplifyConfiguration.builder(context)
.devMenuEnabled(false)
.build()
}
Log output
Fatal Exception: java.lang.RuntimeException: Unable to create application {insert app package}.CustomApplication: AuthException{message=Failed to instantiate AWSMobileClient within 10 seconds, cause=null, recoverySuggestion=Check network connectivity}
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6250)
at android.app.ActivityThread.access$1200(ActivityThread.java:238)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1787)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by com.amplifyframework.auth.AuthException: Failed to instantiate AWSMobileClient within 10 seconds
at com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin.configure(AWSCognitoAuthPlugin.java:88)
at com.amplifyframework.core.category.Category.configure(Category.java:61)
at com.amplifyframework.core.Amplify.configure(Amplify.java:75)
at {insert app package}.initAmplify(CustomApplication.java:50)
at {insert app package}.onCreate(CustomApplication.java:15)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6245)
at android.app.ActivityThread.access$1200(ActivityThread.java:238)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1787)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
amplifyconfiguration.json
{
"api": {
"plugins": {
"awsAPIPlugin": {
"gateway": {
"endpointType": "REST",
"endpoint": "***********",
"region": "********",
"authorizationType": "AWS_IAM"
}
}
}
},
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "**********",
"Region": "***********"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "***************",
"AppClientId": "************",
"AppClientSecret": "***************",
"Region": "************"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH"
}
}
}
}
}
}
GraphQL Schema
// Put your schema below this line
Additional information and screenshots
Firebase device information:

About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (12 by maintainers)
@amitind49 No unfortunately we never managed to figure out why this was happening. Currently the project we had this issue for is not actively being worked on by anyone so sadly I cannot be of much assistance in helping to further debug this issue. If you do end up finding a fix please let me know though.