Android Amplify Authentication with AWSMobileClient crashes at User Sign Up

0

I want to implement a simple signIn/SignUp Functionality in my android app using AWS Cognito and AWS Amplify Authentication.
To make it more easy, I want to use the SignInUI from the AWSMobileClient class.
The UI gets shown with the signIn screen. After selecting the "Sign Up as new user" option I get a signUp screen and I can sign up as a new user. After entering my email and password and clicking "sign up", the new user gets created in my cognito user pool in my AWS console. I also receive the registration code via email. So far so good, but the app crashes with this message:

2020-12-07 19:46:42.250 8018-8018/de.stuttgart.myAppName E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.stuttgart.myAppName , PID: 8018
java.lang.AbstractMethodError: abstract method "void com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler.onSuccess(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser, com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)"
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool$1$1.run(CognitoUserPool.java:424)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

The crash seems to happen in the signUpInBackground() -> onSuccess() method in the CognitoUserPool.java class, I think AWSMobileClient may doesn't know what to do after a successfull singUp. I would like it to show the signIn screen again, so that the signedUp User now can signIn. How do I do that?

When I restart the app, the SignIn screen gets shown again and I can login with this user (after entering the registration code that was sent to my email) and I get redirected to my next Activity (SelectTopCategoryActivity.class) in my App and the user gets confirmed in AWS Cognito. So this works fine.

But why does it crash on SignUp?

I initailize the AWSMobileClient like this in my AuthenticationActivity's "onCreate" method:

AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback<UserStateDetails>() {

        @Override  
        public void onResult(UserStateDetails userStateDetails) {  
            Log.i(TAG, userStateDetails.getUserState().toString());  
            switch (userStateDetails.getUserState()){  
                case SIGNED_IN:  
                    Log.d(TAG, "onResult: Login successful");  
                    Intent i = new Intent(AuthenticationActivity.this, SelectTopCategoryActivity.class);  
                    AuthenticationActivity.this.startActivity(i);  
                    break;  
                case SIGNED_OUT:  
                    showSignIn();  
                    break;  
                default:  
                    AWSMobileClient.getInstance().signOut();  
                    showSignIn();  
                    break;  
            }  
        }  

        @Override  
        public void onError(Exception e) {  
            Log.d(TAG, "onError: error");  
            Log.e(TAG, e.toString());  
        }  
    });  

When the user is not logged in the showSignIn() gets called:

private void showSignIn() {
try {
AWSMobileClient.getInstance().showSignIn(this,
SignInUIOptions.builder().nextActivity(SelectTopCategoryActivity.class).build());
} catch (Exception e) {
Log.d(TAG, "showSignIn: failed");
Log.e(TAG, e.toString());
}
}

my manifest:

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application  
    android:name=".AmplifyAuthentication"  
    android:allowBackup="true"  
    android:icon="@mipmap/ic_launcher"  
    android:label="@string/app_name"  
    android:roundIcon="@mipmap/ic_launcher_round"  
    android:supportsRtl="true"  
    android:theme="@style/AppTheme">  
<!-- <activity android:name=".SwipeActivity">--> <!-- <intent-filter>--> <!-- <action android:name="android.intent.action.MAIN" />--> <!-- <category android:name="android.intent.category.LAUNCHER" />--> <!-- </intent-filter>--> <!-- </activity>-->
    <activity android:name=".AuthenticationActivity">  
        <intent-filter>  
            <action android:name="android.intent.action.MAIN" />  

            <category android:name="android.intent.category.LAUNCHER" />  
        </intent-filter>  
    </activity>  
    <activity android:name=".RecipeActivity" />  
    <activity android:name=".SelectTopCategoryActivity" />  
    <activity android:name=".RecipeListActivity" />  
    <activity android:name=".CircleListActivity" />  
    <activity android:name=".SwipeActivity" />  
</application>  

my build.gradle imports:

dependencies {
def retrofitVersion = "2.9.0"
def lifecycle_version = "1.1.1"
def cardview_version = "1.0.0"
def recyclerView_version = "1.0.0"
def glideVersion = "4.11.0"
def supportVersion = "28.0.0"
def aws_version = "2.13.+"

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'  
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'  

implementation 'androidx.appcompat:appcompat:1.2.0'  
implementation 'com.google.android.material:material:1.2.1'  

// implementation 'com.android.support.constraint:constraint-layout:1.1.3'

testImplementation 'junit:junit:4.+'  
androidTestImplementation 'androidx.test.ext:junit:1.1.2'  
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'  

//retrofit  
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"  
// Retrofit gson converter  
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"  

// ViewModel and LiveData  
implementation "android.arch.lifecycle:extensions:$lifecycle_version"  

// CardViews  
implementation "androidx.cardview:cardview:$cardview_version"  

// RecyclerView  
implementation "androidx.recyclerview:recyclerview:$recyclerView_version"  

//Design library  

implementation "com.android.support:design:$supportVersion"

// Glide  
implementation 'com.github.bumptech.glide:glide:4.8.0'  
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'  

// Circular ImageView  
implementation 'de.hdodenhof:circleimageview:3.1.0'  

// Google Tabs  
implementation "androidx.browser:browser:1.2.0"  

// SwipeCards  
implementation 'com.lorentzos.swipecards:library:1.0.9'  

// Amplify core dependency (for AWS Cognito)  
implementation 'com.amplifyframework:core:1.6.4'  
implementation 'com.amplifyframework:aws-auth-cognito:1.6.4'  

// AWS Dependencies  

implementation "com.amazonaws:aws-android-sdk-core:$aws_version"  
implementation "com.amazonaws:aws-android-sdk-auth-core:$aws_version"  
implementation("com.amazonaws:aws-android-sdk-auth-userpools:$aws_version@aar") { transitive = true }  
implementation("com.amazonaws:aws-android-sdk-auth-ui:$aws_version") { transitive = true }  

// Support for Java 8 features  
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'  

implementation 'com.android.support:appcompat-v7:24.0.0'  
implementation 'com.android.support:design:24.2.1'  

// Mobile Client for initializing the SDK  
implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.6.+@aar') { transitive = true; }  

// Cognito UserPools for SignIn  
implementation 'com.android.support:support-v4:24.+'  
implementation ('com.amazonaws:aws-android-sdk-auth-userpools:2.6.+@aar') { transitive = true; }  

// Sign in UI Library  
implementation 'com.android.support:appcompat-v7:24.+'  
implementation ('com.amazonaws:aws-android-sdk-auth-ui:2.6.+@aar') { transitive = true; }  

}

These are the settings of the cognito user pool, which is referenced in my amplifyconfiguration.json:

'>amplify update auth
Please note that certain attributes may not be overwritten if you choose to use defaults settings.
Using service: Cognito, provided by: awscloudformation
What do you want to do? Walkthrough all the auth configurations
Select the authentication/authorization services that you want to use: User Sign-Up & Sign-In only (Best used with a cloud API only)
Do you want to add User Pool Groups? No
Do you want to add an admin queries API? No
Multifactor authentication (MFA) user login options: OFF
Email based user registration/forgot password: Enabled (Requires per-user email entry at registration)
Please specify an email verification subject: Your verification code
Please specify an email verification message: Your verification code is {####}
Do you want to override the default password policy for this User Pool? Yes
Enter the minimum password length for this User Pool: 6
Select the password character requirements for your userpool:
Specify the app's refresh token expiration period (in days): 30
Do you want to specify the user attributes this app can read and write? No
Do you want to enable any of the following capabilities?
Do you want to use an OAuth flow? No
Warning! Your existing IdentityPool: syzl8795f11f_identitypool_8795f11f will be deleted upon the next “amplify push”!
? Do you want to configure Lambda Triggers for Cognito? No
Successfully updated auth resource syzl8795f11f locally

'>amplify push

Edited by: Grg on Dec 7, 2020 11:16 AM

Edited by: Grg on Dec 7, 2020 11:19 AM

Edited by: Grg on Dec 7, 2020 11:29 AM

Edited by: Grg on Dec 7, 2020 11:33 AM

Grg
asked 4 years ago1046 views
1 Answer
0

Hi @Grg, version 1.6.4 of the Amplify framework depends on 2.19.3_ (https://github.com/aws-amplify/amplify-android/blob/5467886bf890b5c68ac135a4cf6024a51235fd11/build.gradle#L54) of the AWS SDK. Your build.gradle depends on 2.13._ of the AWS SDK, which is not compatible with your version of Amplify (1.6.4), and is likely the reason why you are seeing this crash.

You should not need to depend on the AWS SDK at all, unless you actually need to use AWSMobileClient directly. The recommended approach for new apps though is to just use Amplify, which sits on top of AWSMobileClient. Here is the documentation for signIn with Amplify: https://docs.amplify.aws/lib/auth/signin/q/platform/android

If you do still need to use AWSMobileClient directly, make sure to use the latest version so it is compatible with Amplify, which is 2.19.3.

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions