awslabs / awslabs/aws-mobile-appsync-sdk-android

AWSAppSyncClient to perform API calls, using ClientFactory.java. Error in logcat reads "Please check the AppSync configuration in awsconfiguration.json."

Open
#277 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
106
Forks
56
PR merge metrics
No merged PRs in 30d

Description

Hi,
I am using AWS Amplify and came across some issues. My app logs in perfectly and on restarting the app, the UserState is SIGNED_IN
But when I try to build an appsync client it gives the following exception:

> Please check the AppSync configuration in awsconfiguration.json.

I've copied the code from the AWS Amplify Docs, and my code is the following in ClientFactory.java:

> public static synchronized void init(final Context context) {
> if (client == null) {
> final AWSConfiguration awsConfiguration = new AWSConfiguration(context);
> client = AWSAppSyncClient.builder()
> .context(context)
> .awsConfiguration(awsConfiguration)
> .cognitoUserPoolsAuthProvider(new CognitoUserPoolsAuthProvider() {
> @Override
> public String getLatestAuthToken() {
> try {
> return AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString();
> } catch (Exception e){
> Log.e("APPSYNC_ERROR", e.getLocalizedMessage());
> return e.getLocalizedMessage();
> }
> }
> }).build();
> }
> }

My logcat has the following messages:

`Caused by: java.lang.RuntimeException: Please check the AppSync configuration in awsconfiguration.json.
at com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient$Builder.build(AWSAppSyncClient.java:485)
at com.example.events.ClientFactory.init(ClientFactory.java:31)
at com.example.events.MainActivity.onCreate(MainActivity.java:69)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Caused by: java.lang.RuntimeException: Found conflicting AuthMode. Should be API_KEY but you selected AMAZON_COGNITO_USER_POOLS`

My app crashes on start and I'm not quite sure how to fix this. Any advice would be greatly appreciated!

Contributor guide

Open the contributing guide

Research direction

Begin with ClientFactory.java:31 and MainActivity.java:69, then inspect awsconfiguration.json and AWSAppSyncClient.Builder.build at the logged SDK location. Compare the configured and selected authentication modes; done means the client initializes without the conflicting-AuthMode exception and the app no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, aws, java
Domain
api, authentication, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.