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

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

Open
6 tasks done
dmichelutti opened this issue Dec 22, 2023 · 7 comments
Open
6 tasks done
Labels
bug This points to a verified bug in the code

Comments

@dmichelutti
Copy link

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

@dmichelutti dmichelutti added the bug This points to a verified bug in the code label Dec 22, 2023
@poovamraj
Copy link
Contributor

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

@dmichelutti
Copy link
Author

dmichelutti commented Jan 2, 2024

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
Copy link
Contributor

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

@dmichelutti
Copy link
Author

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

@dmichelutti
Copy link
Author

dmichelutti commented Jan 10, 2024

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

@poovamraj
Copy link
Contributor

@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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

No branches or pull requests

2 participants