Closed crawford-jake closed 2 years ago
@crawford-jake Thanks for submitting this - we are taking a look.
I can reproduce on Flutter stable and master. Related Flutter issue: https://github.com/flutter/flutter/issues/28651
@crawford-jake We are in the midst of reviewing/testing a fix.
@haverchuck Thank you!
@crawford-jake Can you please give version 0.4.4 a try?
@haverchuck It's working great on Amplify 0.4.4 with flutter stable 2.10.4. I want to give our QA team a chance to test this in our app. Following that i'll close the issue. Thank you for the quick fix! You guys rock :)
@haverchuck It's working great, thanks so much again! I just had a quick question about the 2 second timeout in FlutterAuthProvider.swift/kt. When we launch the app we setup some streams and queries. However on a cache miss or the token expires, the server takes longer than two seconds to deliver the request. So for example if the token is delivered in 2.1 seconds Amplify will throw and doesn't retry. Would a retry be something we should handle client side, or something you could easily patch?
@crawford-jake We can bump that timeout threshhold for now, until we decide on a way to make it configurable. Would that be helpful?
@haverchuck Yep, that would be great.
@crawford-jake Ok, we will make this change soon. I'll keep this issue open to track it.
@haverchuck We found another issue similar to above. Using the same steps as above, change the query in the ExampleAmplifyCall to a stream. Then on iOS open the app in release mode on a physical device, verify the stream established successfully, move the app to the background (don't close, just open another app), and after some time return to the example app.
This gives us the following error in XCODE: Error in subscription stream: ApiException(message: Subscription item event failed with error, recoverySuggestion: , underlyingException: The operation couldn’t be completed. (AppSyncRealTimeClient.ConnectionProviderError error 3.))
After this occurs, streams no longer update. I will provide more detailed steps if necessary.
Thanks!
@crawford-jake We've updated the timeout you called out previously in version 0.4.5.
@haverchuck Thank you!
This issue has been fix since version 0.4.4.
Description
When I configure Amplify using a custom FunctionAuthProvider, the method channel fails to call getLatestAuthToken when the app state changes. This does not occur for api authorizations that do not use the FunctionAuthProvider class. Seemingly because the method channel call in FlutterAuthProvider.kt is avoided.
When the app reopens from a state change
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++
is thrown on all API requests. I have confirmed that the method channel call to retrieve the custom token fails.Our QA team has reported the same issue coming from their iOS devices as well, however it is easiest to reproduce in Android.
Categories
Steps to Reproduce
Steps to Reproduce
1. Create a new flutter project on the stable channel
Run the following commands in the terminal
flutter channel stable
flutter create amplify_bug
cd amplify_bug
flutter pub cache clean
flutter pub get
Setup iOS for Amplify Modify the ios/Podfile and replace the second line with:
platform :ios, '11.0'
cd ios && pod install
Setup Android for Amplify Modify the android/app/build.gradle to the minSdkVersion 21
Confirm the project runs on the iOS simulator and Android emulator
flutter pub get
flutter run
2. Install amplify_flutter 0.4.3 and amplify_api 0.4.3
Open pubspec.yaml and add the following dependencies
Then confirm that these packages run
flutter pub get
flutter run
3. Configure Amplify with FunctionAuthProvider and setup working Amplify Query
Create a new .dart file in the lib directory, and copy the following. (To see this render your will need to set this as the home widget in main.dart)
You will find three errors: amplifyconfig_customAuth, ExampleAmplifyCall, and CustomAuthProvider To resolve amplifyconfig_customAuth, set it to the following (Please note you will need to provide your own API Key, endpoint, and friendly name):
This configuration has been set referencing the following Amplify/AWS Lambda documentation
To resolve CustomAuthProvider, add the following:
Note: This will need to be a valid Bearer token, intended to be used for endpoint you stated in amplifyconfig_customAuth
To resolve ExampleAmplifyCall, add the following to a new dart file and import where necessary:
Note: Any graphQL request that works with your specified endpoint will do.
You should now be able to run the flutter app, and tap "RUN QUERY" to see Amplify data print in the console (Assuming your amplify configuration, token, and query is correct).
4. Break Amplify
Run the flutter app on an Android Emulator. After confirming the query completes successfully, click the Android back button to return to the Android home screen.
Wait on the phone home screen for several seconds, then click on the "Recently used apps" button, and select the flutter app. When Amplify has been configured, you will be able to click on "RUN QUERY" again. This time however, you will see the following error:
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: com.amazonaws.amplify/api. Response ID: 11
I have found that the error being thrown is from the FlutterAuthProvider.kt file in the android api folder. When you are debugging, you will find that when the app restarts that getLatestAuthToken in the dart file we created is not reached because of a disconnect in the method channel.
If you would like to quickly see this error disappear, change the authorizationType in the amplify configuration to
"authorizationType": "AWS_LAMBDA"
and initialize Amplify with the following:By simply changing our code to an API key, we resolved the JNI Issue
Screenshots
https://user-images.githubusercontent.com/82613137/161838322-8ab8b40e-df2b-4bea-8b19-4f177ded3177.mov
Platforms
Environment
Dependencies
Device
Pixel 4 Emulator API 30
OS
Android
CLI Version
7.6.26 (The configuration in the example is manually set from the Flutter Amplify API Docs)
Additional Context
No response