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

No implementation found for method configure on channel com.amazonaws.amplify/core - on Android back button click #99

Closed
fjnoyp opened this issue Sep 2, 2020 · 7 comments · Fixed by #345
Labels
Android Issues specific to the Android Platform bug Something is not working; the issue has reproducible steps and has been reproduced pending-release Issues that have been addressed in main but have not been released

Comments

@fjnoyp
Copy link
Contributor

fjnoyp commented Sep 2, 2020

  1. On Android, run the example app
  2. When the LandingPage is shown with the "Sign In" and "Sign Up" buttons, hit the back button until the Android home screen is displayed.
  3. Hit the Android app switcher button (rightmost) and return to the example app. App stays on the LoadingPage.
    Console log shows:
    E/flutter (31034): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method configure on channel com.amazonaws.amplify/core)
    E/flutter (31034): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:7)
    E/flutter (31034):
    E/flutter (31034): Initial Commit #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
    E/flutter (31034): feat(amplify_core): initial commit for amplify-flutter #2 MethodChannelAmplifyCore.configure (package:amplify_core_plugin_interface/method_channel_amplify.dart:25:21)
    E/flutter (31034): feat(amplify_auth_cognito): initial commit for amplify_auth_cognito and amplify_auth_plugin_interface #3 Amplify.configure (package:amplify_core/amplify_core.dart:71:35)
    E/flutter (31034): Amplify analytics #4 _MyAppState._initAmplifyFlutter (package:sample_app/main.dart:61:19)
    E/flutter (31034): [RFC]: Amplify Flutter #5 _MyAppState.initState (package:sample_app/main.dart:52:5)
    E/flutter (31034): feat(amplify_analytics): initial commit #6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
    E/flutter (31034): Amplify analytics #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
    E/flutter (31034): Initial Commit - Sample App #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
    E/flutter (31034): ci: add CircleCI config for running unit tests #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
    E/flutter (31034): feat(amplify_auth_cognito): signIn, confirmSignIn, confirmSignUp and signOut #10 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1174:16)
    E/flutter (31034): feat(amplify_auth_cognito): confirmSignUp, signIn, confirmSignIn, signOut #11 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1145:5)
    E/flutter (31034): WIP: Readme #12 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1087:17)
    E/flutter (31034): feat(amplify_auth_cognito) password management and hub events #13 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:19)
    E/flutter (31034): feat(amplify_auth_cognito): password management and events #14 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1086:13)
    E/flutter (31034): feat(amplify_storage_s3): UploadFile and GetUrl #15 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:927:7)
    E/flutter (31034): feat(ampify_auth_cognito): credentials #16 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:908:7)
    E/flutter (31034): Android unit tests analytics #17 _rootRun (dart:async/zone.dart:1182:47)

Originally posted by @kjones in #80 (comment)

@fjnoyp
Copy link
Contributor Author

fjnoyp commented Sep 2, 2020

This issue does not happen when the app is backgrounded using the other Android bottom bar buttons.

To reproduce, the Android back button must be pressed. The app is still backgrounded but the issue occurs afterwards.

@fjnoyp
Copy link
Contributor Author

fjnoyp commented Sep 2, 2020

Looking at Flutter logs, one can see an inconsistency from Flutter in how the app is "backgrounded". If the app is backgrounded using the other Android bottom bar buttons the following lifecycle events occur:

D/AutoSessionTracker( 8274): Activity paused: MainActivity
D/AutoSessionTracker( 8274): Activity stopped: MainActivity
D/AutoSessionTracker( 8274): Activity state saved: MainActivity
D/AutoSessionTracker( 8274): Activity started: MainActivity
D/AutoSessionTracker( 8274): Activity resumed: MainActivity

In this case the app state is still preserved.

@fjnoyp
Copy link
Contributor Author

fjnoyp commented Sep 2, 2020

However, when pressing the back button, the destroy lifecycle events occurs. At this point app state is lost and the crash will occur in the logs. Our Flutter app is now in an inconsistent state and probably not recoverable ...

D/AutoSessionTracker( 8274): Activity paused: MainActivity
D/AutoSessionTracker( 8274): Activity stopped: MainActivity
D/AutoSessionTracker( 8274): Activity destroyed MainActivity

I find it a bit strange why Flutter would destroy the MainActivity, yet still have the app "running" (ie. accessible as one of the backgrounded apps).

@fjnoyp fjnoyp added Android Issues specific to the Android Platform bug Something is not working; the issue has reproducible steps and has been reproduced help wanted labels Sep 2, 2020
@Amplifiyer
Copy link
Contributor

This seems like an issue where the back button causes the FlutterActivity to be destroyed in Android instead of sending it to background. There are some workarounds mentioned here https://stackoverflow.com/questions/55539302/sending-your-application-to-background-when-back-button-is-pressed-in-flutter that can be used by the applications such as

We will discuss if it makes sense to provide such workarounds in the Amplify libraries or wait until Flutter provides a more standard solution.

@Amplifiyer
Copy link
Contributor

We discussed internally and it doesn't make sense for Amplify to provide a workaround in the library. As mentioned in the previous comment there are workarounds that can be done in the applications.

@alextekartik
Copy link

alextekartik commented Jan 20, 2021

In my experiment, this happens because cognito flutter registration fails (yes it can be called twice in this situation, see #312). Other plugins (I know for having dealing with this in my sqflite plugin) such as firebase handles this case gracefully.

@Amplifiyer
Copy link
Contributor

Amplifiyer commented Jan 27, 2021

Reopening this as we did more deep dive into this and found out the root cause that is causing this issue. It is true that flutter's activity gets killed on the back button, however on resuming the application, flutter recreates the activity.

This assumes that the platform plugin's initialization code is idempotent which is not the case with amplify-flutter since underlying libraries can only be configured (and adding plugins) only once, repeated calls return an exception. e.g. AnalyticsPlugin

Flutter activity however swallows the exception (no error logs printed either) and fails to initialize the platform plugins resulting in the exception mentioned in this issue.

The fix would be to make platform plugins' init code idempotent (catching and swallowing the specific exception about reconfiguration). Since the dart activity gets recreated again as well (initState) gets called again, amplify-flutter customers would also have to catch and ignore AmplifyAlreadyConfiguredException if the Amplify is being configured in the initState

@Amplifiyer Amplifiyer reopened this Jan 27, 2021
@Amplifiyer Amplifiyer added pending-release Issues that have been addressed in main but have not been released and removed help wanted labels Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues specific to the Android Platform bug Something is not working; the issue has reproducible steps and has been reproduced pending-release Issues that have been addressed in main but have not been released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants