Crash when calling loginWithBrowser with targetSdk 34 in build.gradle
dmichelutti opened this issue · 7 comments
Checklist
- The issue can be reproduced in the Auth0.Android sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
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 can you share how the code is being called?
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.
Makes sense but from the error message, I wanted to know whether this is being called from an Activity or another component
I'm calling that function from an Activity, a simple Activity with a Login button.
Any news? This issue is blocking the release on Play Store, because now the targetSdk must be >= 33
@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?
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.