aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.3k stars 239 forks source link

DataStore queries do not complete on second app load on Android 7 #2055

Open HarkerTech opened 1 year ago

HarkerTech commented 1 year ago

Description

Have seen this issue in our production app, however we have also replicated it in the tutorial amplified_todo app (https://docs.amplify.aws/start/getting-started/add-api/q/integration/flutter/).

On a fresh boot (delete app on emulator and rebuild) the first DataStore sync/observeQuery runs as expected and returns results. However after restarting the app after the successful sync the query will fail to return any results. We did not observe any errors in the logs.

Have not tested on Android versions older than API 24, however on API 26 the queries completed successfully.

Categories

Steps to Reproduce

  1. Go through the AWS Amplify tutorial for Flutter (https://docs.amplify.aws/start/getting-started/add-api/q/integration/flutter/)
  2. Build and deploy on a Android 7 (API 24/25) emulator
  3. After app loads, restart the app
  4. App should continuously show loading indicator

Screenshots

No response

Platforms

Android Device/Emulator API Level

API 24, API 25

Environment

amplified_todo % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.5.1 21G83 darwin-arm, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio
[✓] VS Code (version 1.70.2)
[✓] Connected device (5 available)
[✓] HTTP Host Availability

• No issues found!

Dependencies

amplified_todo % flutter pub deps --no-dev --style=compact
Dart SDK 2.17.6
Flutter SDK 3.0.5
amplified_todo 1.0.0+1

dependencies:
- amplify_api 0.6.6 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.6 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_datastore 0.6.6 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.6.6 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- cupertino_icons 1.0.5
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]

transitive dependencies:
- amplify_api_android 0.6.6 [flutter]
- amplify_api_ios 0.6.6 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.6 [flutter]
- amplify_auth_cognito_ios 0.6.6 [amplify_core flutter]
- amplify_core 0.6.6 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.6 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.6 [flutter]
- amplify_flutter_ios 0.6.6 [amplify_core flutter]
- async 2.8.2 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- crypto 3.0.2 [typed_data]
- http 0.13.5 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- intl 0.17.0 [clock path]
- json_annotation 4.6.0 [meta]
- material_color_utilities 0.1.4
- meta 1.7.0
- path 1.8.1
- plugin_platform_interface 2.1.2 [meta]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2

Device

Huawei P9

OS

Android 7.0

Deployment Method

Amplify CLI

CLI Version

9.2.1

Additional Context

No response

Amplify Config

const amplifyconfig = ''' { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "api": { "plugins": { "awsAPIPlugin": { "AmplifiedTODO": { "endpointType": "GraphQL", "endpoint": "", "region": "ap-southeast-2", "authorizationType": "API_KEY", "apiKey": "" } } } }, "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "AppSync": { "Default": { "ApiUrl": "", "Region": "ap-southeast-2", "AuthMode": "API_KEY", "ApiKey": "", "ClientDatabasePrefix": "AmplifiedTODO_API_KEY" }, "AmplifiedTODO_AWS_IAM": { "ApiUrl": "", "Region": "ap-southeast-2", "AuthMode": "AWS_IAM", "ClientDatabasePrefix": "AmplifiedTODO_AWS_IAM" } }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "", "Region": "ap-southeast-2" } } }, "CognitoUserPool": { "Default": { "PoolId": "", "AppClientId": "", "Region": "ap-southeast-2" } }, "Auth": { "Default": { "authenticationFlowType": "USER_SRP_AUTH", "socialProviders": [], "usernameAttributes": [ "EMAIL" ], "signupAttributes": [], "passwordProtectionSettings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [ "REQUIRES_LOWERCASE", "REQUIRES_NUMBERS", "REQUIRES_SYMBOLS", "REQUIRES_UPPERCASE" ] }, "mfaConfiguration": "OFF", "mfaTypes": [ "SMS" ], "verificationMechanisms": [ "EMAIL" ] } } } } } }''';

fjnoyp commented 1 year ago

Hi @HarkerTech will take a look using our datastore example app to reproduce

fjnoyp commented 1 year ago

Hi @HarkerTech thank you for submitting this issue. I am able to reproduce this issue in our Datastore example app.

On Android 30, I am able to save Blog/Post objects and see those objects on app restarts.

On Android 25, I am able to save Blog/Post objects but sometimes they do not appear in the list of saved models. Regardless they are all lost on app restart. However, the save method succeeds, and those Blog/Post objects are displayed on the Android 30 device.

ObserveQuery.listen is not being called at all for Blog/Post (which have fields) while it is still called for Comment (of which there are none). It seems when a list should be returned for ObserveQuery listen something on the native side is breaking that is causing listen to not be called on the Dart side.

We'll look into this more internally. Might be an issue with underlying Amplify Android.

Jordan-Nelson commented 3 weeks ago

@HarkerTech - Apologies for the long delay in an update. I attempted to reproduce this with the latest version of Amplify Flutter (2.0) and was unable to. If you are still facing this issue can you attempt to reproduce with the latest version? It is possible this was previously an issue that has been fixed since. If you can still reproduce this, can you provide the schema you are using? Thanks.

Also please note that you will need to follow these set up steps to support API level 24 - https://docs.amplify.aws/gen1/flutter/build-a-backend/more-features/datastore/set-up-datastore/#update-the-android-project

Jordan-Nelson commented 3 weeks ago

@HarkerTech - I am going to change this to a docs issue. While I was able to get this working in the example app in this repo, the set up steps linked above seem insufficient for a new Flutter app. I think there may be some set up steps missing from our docs for the latest version of Flutter / Amplify Flutter.