auth0 / Auth0.Android

Android toolkit for Auth0 API
https://auth0.com
MIT License
208 stars 130 forks source link

Crash when calling loginWithBrowser with targetSdk 34 in build.gradle #707

Open dmichelutti opened 7 months ago

dmichelutti commented 7 months ago

Checklist

Description

Targeting Android application to latest sdk (targetSdk = 34 inside defaultConfig in build.gradle) the application crashes at login with this stackTrace:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? : android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ContextImpl.startActivity(ContextImpl.java:1127) at android.app.ContextImpl.startActivity(ContextImpl.java:1103) at android.content.ContextWrapper.startActivity(ContextWrapper.java:436) at com.auth0.android.provider.AuthenticationActivity$Companion.authenticateUsingBrowser$auth0_release(AuthenticationActivity.kt:120) at com.auth0.android.provider.OAuthManager.startAuthentication(OAuthManager.kt:67) at com.auth0.android.provider.WebAuthProvider$Builder.start(WebAuthProvider.kt:522)

For our solution I have deleted (temporary) targetSdk variable from build.gradle, but the application will show an annoying popup at the beginning, showing the application is done for oler versions of Android.

Reproduction

1 - Start an application with Auth0 library WITHOUT targetSdk flag in build.gradle 2 - Call loginWithBrowser method and all will work fine 3 - Add targetSdk = 34 (also 33 will do the job) and refresh gradle 4 - Now calling loginWithBrowser method will crash

Additional context

No response

Auth0.Android version

2.10.2

Android version(s)

14

poovamraj commented 6 months ago

@dmichelutti can you share how the code is being called?

dmichelutti commented 6 months ago

Hi @poovamraj , I simply call the function like the example does.

` val builder = WebAuthProvider .login(myAccount) .withScheme(myScheme) .withScope(myScope) .withTrustedWebActivity() .withAudience(myAudience!!) .withOrganization(myOrganization!!)

    builder.start(appContext, object : Callback<Credentials, AuthenticationException> {
        override fun onSuccess(result: Credentials) {
            onSuccess(result)
        }
        override fun onFailure(error: AuthenticationException) {
            onError(error)
        }
    })`

This code will work propery as long as I put "targetSdk = 34" inside my build.gradle file. With this property the crash appears.

poovamraj commented 6 months ago

Makes sense but from the error message, I wanted to know whether this is being called from an Activity or another component

dmichelutti commented 6 months ago

I'm calling that function from an Activity, a simple Activity with a Login button.

dmichelutti commented 6 months ago

Any news? This issue is blocking the release on Play Store, because now the targetSdk must be >= 33

poovamraj commented 5 months ago

@dmichelutti I am not able to reproduce this issue on our end. Can you reproduce this issue in our sample app and provide the fork here (without secrets) - https://github.com/auth0-samples/auth0-android-sample/tree/master/00-Login-Kt?

dmichelutti commented 5 months ago

Hi @poovamraj I think I have found the source of the problem. In the project there was not a direct Activity intent call, but the builder was managed inside a DI implementation (Hilt Dagger). Passing the activity to this DI managed class will work, but can generate some memory leaks. Moving the builder back inside the Activity is the only possible solution, and it works. I don't know if you have planned, inside your roadmap, to manage also the intent calls also passing an Application Context, instead of an Activity.