Auth0.Android icon indicating copy to clipboard operation
Auth0.Android copied to clipboard

Crash when calling loginWithBrowser with targetSdk 34 in build.gradle

Open dmichelutti opened this issue 2 years ago • 7 comments

Checklist

  • [X] The issue can be reproduced in the Auth0.Android sample app (or N/A).
  • [X] I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • [X] I have looked into the API documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] 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 avatar Dec 22 '23 17:12 dmichelutti

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

poovamraj avatar Jan 02 '24 09:01 poovamraj

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.

dmichelutti avatar Jan 02 '24 16:01 dmichelutti

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

poovamraj avatar Jan 04 '24 12:01 poovamraj

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

dmichelutti avatar Jan 05 '24 15:01 dmichelutti

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

dmichelutti avatar Jan 10 '24 23:01 dmichelutti

@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?

poovamraj avatar Feb 02 '24 11:02 poovamraj

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.

dmichelutti avatar Feb 07 '24 10:02 dmichelutti

@dmichelutti , Are you still facing this issue. We have observed this occurs when you pass context other than an ActivityContext as the parameter.

pmathew92 avatar Dec 12 '24 06:12 pmathew92

I am closing this issue due to inactivity for the time being. Please fee free to reopen if you are encountering the same . Meanwhile we will update the docs to specify passing an activity context

pmathew92 avatar Dec 18 '24 06:12 pmathew92