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

Cognito Error during Android plugin registration: The client tried to add a plugin after calling configure. #312

Closed
alextekartik opened this issue Jan 19, 2021 · 4 comments

Comments

@alextekartik
Copy link

Describe the bug

In some specific Android restart scenario AuthCognito plugin fails to register (typically the second time).

To Reproduce

Unfortunately I don't a small project to reproduce. But basically, there is a crash when:

  • Having amplify_auth_cognito 0.0.1-dev.6
  • Launch and login using AWS Cognito and flutter example
  • exiting the Android application using Back (not killing the application)
  • starting the application again from the android launcher (not the IDE)

Expected behavior

Pluging Registration ok. When plugin registration fails, we end up with a Missing Plugin Exception (that could happen on other plug).

Screenshots

I had to override GeneratedPluginRegistrant.registerWith to catch the logs in MainActivity.configureFlutterEngine with something like that

        String name = "AuthCognito";
        try {
            Log.e("StableApp", "registering " + name);
            flutterEngine.getPlugins().add(new com.amazonaws.amplify.amplify_auth_cognito.AuthCognito());
        } catch (Exception e) {
            Log.e("StableApp", "Error " + name, e);
        }

Logs:

    AmplifyException{message=The client tried to add a plugin after calling configure()., cause=null, recoverySuggestion=Plugins may not be added or removed after configure(...) is called.}
        at com.amplifyframework.core.Amplify.updatePluginRegistry(Amplify.java:195)
        at com.amplifyframework.core.Amplify.addPlugin(Amplify.java:175)
        at com.amazonaws.amplify.amplify_auth_cognito.AuthCognito.onAttachedToEngine(AuthCognito.kt:92)
        at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.add(FlutterEngineConnectionRegistry.java:143)
        at com.example.stable_app.StableAppPluginRegistrant.registerWith(StableAppPluginRegistrant.java:29)
        at com.example.stable_app.MainActivity.configureFlutterEngine(MainActivity.kt:10)
        at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:180)
        at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:409)

There are also some additiontial logs during Code initialization:

2021-01-19 15:44:59.408 29375-29375/? E/StableApp: registering AmplifyCore
2021-01-19 15:44:59.411 29375-29375/? W/System.err: java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)
2021-01-19 15:44:59.411 29375-29375/? W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:496)
2021-01-19 15:44:59.411 29375-29375/? W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
2021-01-19 15:44:59.411 29375-29375/? W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.output.FileOutput.openFile(FileOutput.java:67)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.output.FileOutput.startup(FileOutput.java:49)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Agent.startup(Agent.java:122)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Agent.getInstance(Agent.java:50)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Offline.<clinit>(Offline.java:31)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Offline.getProbes(Offline.java:51)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at com.amazonaws.amplify.amplify_core.Core.$jacocoInit(Unknown Source:13)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at com.amazonaws.amplify.amplify_core.Core.<clinit>(Unknown Source:0)
2021-01-19 15:44:59.412 29375-29375/? W/System.err:     at com.example.stable_app.StableAppPluginRegistrant.registerWith(StableAppPluginRegistrant.java:22)

Platform

Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply):
[x] Android
[ ] iOS (not tested)

Smartphone (please complete the following information):

  • Emulator API 29

Additional context

  • I notice this issue first in release mode.
  • All other plugins (path_provider, sqflite register correctly)
  • If you kill the app and restart the app, it works fine. Quitting with back does not kill the java world and restarting again here cause the issue again.
  • Sorry for not having a better description...
@fjnoyp
Copy link
Contributor

fjnoyp commented Jan 20, 2021

Hi @alextekartik please see this issue: #99

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

https://medium.com/stuart-engineering/%EF%B8%8F-the-tricky-task-of-keeping-flutter-running-on-android-2d51bbc60882
https://www.programmersought.com/article/3839440802/

@alextekartik
Copy link
Author

Thanks @fjnoyp for the info.

Pressing back is a common task, and killing the FlutterActivity can happen in low memory situation (which is hard to reproduce so pressing back is a way to mimic what would happen). Other plugins deal with the situation on the native side (i.e. the issue only happens with the cognito plugin for the 10+ plugins I have). If you get a Missing plugin exception on issue #99, it is just because the registration fails which could be solved on the native side.

@fjnoyp
Copy link
Contributor

fjnoyp commented Jan 20, 2021

Thanks for that insight @alextekartik I'll investigate what you said.

@Amplifiyer
Copy link
Contributor

This is fixed in #345 which will be part of next release. You would have to still catch the exception AmplifyAlreadyConfiguredException from Amplify.configure()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants