Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: AnalyticsException(message: Unable to read appId or region from the amplify configuration json., recoverySuggestion: Make sure amplifyconfiguration.json is a valid json object in expected format. #1071

Closed
bermanapps opened this issue Nov 10, 2021 · 3 comments
Labels
analytics Issues related to the Amplify Analytics Category pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.

Comments

@bermanapps
Copy link

bermanapps commented Nov 10, 2021

I downloaded this sample project:

But I get the following error, when caled Amplify.configue(amplifyconfig):

E/flutter ( 5798): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: AnalyticsException(message: Unable to read appId or region from the amplify configuration json., recoverySuggestion: Make sure amplifyconfiguration.json is a valid json object in expected format. Please take a look at the documentation for expected format of amplifyconfiguration.json., underlyingException: org.json.JSONException: No value for pinpointAnalytics) E/flutter ( 5798): #0 AmplifyClass.configure (package:amplify_flutter/amplify.dart:171:9) E/flutter ( 5798): E/flutter ( 5798): #1 _MyAppState._initAmplifyFlutter (package:sample_app/main.dart:65:7) E/flutter ( 5798): E/flutter ( 5798):

This is some of the code:

@OverRide
initState() {
super.initState();
_initAmplifyFlutter();
}

void _initAmplifyFlutter() async {
AmplifyAuthCognito auth = AmplifyAuthCognito();
AmplifyStorageS3 storage = AmplifyStorageS3();
AmplifyAnalyticsPinpoint analytics = AmplifyAnalyticsPinpoint();

Amplify.addPlugins([auth, storage, analytics]);

// Initialize AmplifyFlutter
try {
  await Amplify.configure(amplifyconfig);
} on AmplifyAlreadyConfiguredException {
  print(
      "Amplify was already configured. Looks like app restarted on android.");
}

setState(() {
  _isAmplifyConfigured = true;
});

}
Also, my amplifyconfiguation.dart seems to look fine;

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-1:xxxxxxxxxxxx-5ce7-44e6-807d-xxxxxxxxxx",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-1_xxxxxxxx",
                        "AppClientId": "xxxxxxxxxxxxx",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "loginMechanisms": [
                            "PREFERRED_USERNAME"
                        ],
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "xxxxxxxxxxxxx-dev",
                        "Region": "us-east-1"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "xxxxxxxxxxxx-dev",
                "region": "us-east-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}''';

I have run:

amplify add auth
amplify add storage
amplify push
Here are my dependancies in pubspec.yaml

file_picker: ^4.0.0
amplify_flutter: 0.2.7
amplify_analytics_pinpoint: 0.2.7
amplify_auth_cognito: 0.2.7
amplify_storage_s3: 0.2.7
Still no luck. Thanks

@HuiSF HuiSF added the analytics Issues related to the Amplify Analytics Category label Nov 11, 2021
@HuiSF
Copy link
Contributor

HuiSF commented Nov 11, 2021

Hi @bermanapps Thanks for reporting this issue. A quick note - please be careful when sharing the config file, it contains credentials of your AWS services. Please be sure you have those sensitive fields masked before pasting and posting.

@HuiSF
Copy link
Contributor

HuiSF commented Nov 11, 2021

Looking the content of your amplifyconfiguration.dart, it looks like you haven't added Analytic category via Amplify CLI, or you haven't pulled Analytic configuration yet. After you complete necessary steps, you should be able see a new key analytics aside auth and storage.

@HuiSF HuiSF added the pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. label Nov 11, 2021
@bermanapps
Copy link
Author

Thanks, this solved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analytics Issues related to the Amplify Analytics Category pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants