Skip to content

Android: App crashes if the authentication dialog is canceled #17

@gkontokotsios

Description

@gkontokotsios

Hey Josh,

Thanks for this library! One issue I noticed is that my app is crashing when I click the "Cancel" button in the authentication dialog.

This is the exception:

I/flutter (10367): 2023-10-18 10:34:32.353207 - [INFO] AuthService: Launching authentication
V/CallbackHelper(10367): The Callback URI is: myApplicationScheme://auth0.url.com/android/my.package.name/callback
V/OAuthManager(10367): Using PKCE authentication flow
D/OAuthManager(10367): Using the following Authorize URI: https://auth0.url.com/authorize?...
I/flutter (10367): 2023-10-18 10:34:32.447434 - [INFO] LifeCycleHandler: SystemChannels> AppLifecycleState.inactive.  
D/TWAProviderPicker(10367): Found TWA provider, finishing search: com.android.chrome
I/flutter (10367): 2023-10-18 10:34:33.546646 - [INFO] LifeCycleHandler: SystemChannels> AppLifecycleState.paused.  
D/AndroidRuntime(10367): Shutting down VM
E/AndroidRuntime(10367): FATAL EXCEPTION: main
E/AndroidRuntime(10367): Process: my.package.name, PID: 10367
E/AndroidRuntime(10367): java.lang.RuntimeException: Unable to resume activity {my.package.name/com.auth0.android.provider.AuthenticationActivity}: java.lang.IllegalArgumentException: Unsupported value: 'io.flutter.embedding.android.FlutterActivity@73487e2' of type 'class io.flutter.embedding.android.FlutterActivity'
E/AndroidRuntime(10367): 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4824)
E/AndroidRuntime(10367): 	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4857)
E/AndroidRuntime(10367): 	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
E/AndroidRuntime(10367): 	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime(10367): 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
E/AndroidRuntime(10367): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
E/AndroidRuntime(10367): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
E/AndroidRuntime(10367): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(10367): 	at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(10367): 	at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(10367): 	at android.app.ActivityThread.main(ActivityThread.java:7870)
E/AndroidRuntime(10367): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10367): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(10367): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(10367): Caused by: java.lang.IllegalArgumentException: Unsupported value: 'io.flutter.embedding.android.FlutterActivity@73487e2' of type 'class io.flutter.embedding.android.FlutterActivity'
E/AndroidRuntime(10367): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:292)
E/AndroidRuntime(10367): 	at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:75)
E/AndroidRuntime(10367): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:272)
E/AndroidRuntime(10367): 	at com.jfacoustic.flutter_auth0_client.FlutterAuth0ClientPlugin$login$1.onFailure(FlutterAuth0ClientPlugin.kt:76)
E/AndroidRuntime(10367): 	at com.jfacoustic.flutter_auth0_client.FlutterAuth0ClientPlugin$login$1.onFailure(FlutterAuth0ClientPlugin.kt:73)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.OAuthManager.resume(OAuthManager.kt:85)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.WebAuthProvider.resume(WebAuthProvider.kt:77)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.AuthenticationActivity.deliverAuthenticationResult$auth0_release(AuthenticationActivity.kt:94)
E/AndroidRuntime(10367): 	at com.auth0.android.provider.AuthenticationActivity.onResume(AuthenticationActivity.kt:58)
E/AndroidRuntime(10367): 	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1488)
E/AndroidRuntime(10367): 	at android.app.Activity.performResume(Activity.java:8197)
E/AndroidRuntime(10367): 	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4814)
E/AndroidRuntime(10367): 	... 13 more

The exception seems to indicate that the issues is coming from:
FlutterAuth0ClientPlugin.kt:76

Flutter Doctor Output:

[✓] Flutter (Channel stable, 2.10.5, on macOS 14.0 23A344 darwin-arm, locale en-GB)
    • Flutter version 2.10.5 at /opt/homebrew/Caskroom/flutter@2/2.10.5/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (1 year, 6 months ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/myUser/Library/Android/sdk
    • Platform android-33, build-tools 34.0.0
    • Java binary at: /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment Temurin-11.0.19+7 (build 11.0.19+7)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.3)
    • Android Studio at /Users/myUser/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
    • IntelliJ at /Users/myUser/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 75.1.4
    • Dart plugin version 232.10072.19

If you are willing to provide some feedback or tips, I will fix the issue myself and I will open a pull request. It's just that currently I'm not sure what is going on, is it maybe that result.error("AuthenticationException", exception.message, activity) is expecting an activity of type android.app.Activity and not one of type io.flutter.embedding.android.FlutterActivity?

Thanks in advance!

Best,
George

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions