FirebaseUI-Android: Requires IMMUTABLE tag crash on API 31

Step 2: Describe your environment

  • Android device: Google Pixel 4 emulator
  • Android OS version: Api 31
  • Google Play Services version: 4.3.10
  • Firebase/Play Services SDK version: Firebase BOM 28.3.1
  • FirebaseUI version: 8.0.0

Step 3: Describe the problem:

Steps to reproduce:

Clicking on button to open Auth activity crashes app

Observed Results:

  • 2021-09-01 19:52:52.192 8005-8005/hr.pavetic.simplify.debug E/AndroidRuntime: FATAL EXCEPTION: main Process: hr.pavetic.simplify.debug, PID: 8005 java.lang.IllegalArgumentException: hr.pavetic.simplify.debug: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. at android.app.PendingIntent.checkFlags(PendingIntent.java:375) at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458) at android.app.PendingIntent.getActivity(PendingIntent.java:444) at android.app.PendingIntent.getActivity(PendingIntent.java:408) at com.google.android.gms.internal.auth-api.zzr.zzc(com.google.android.gms:play-services-auth@@19.0.0:19) at com.google.android.gms.auth.api.credentials.CredentialsClient.getHintPickerIntent(com.google.android.gms:play-services-auth@@19.0.0:10) at com.firebase.ui.auth.ui.phone.CheckPhoneHandler.fetchCredential(CheckPhoneHandler.java:28) at com.firebase.ui.auth.ui.phone.CheckPhoneNumberFragment.setDefaultCountryForSpinner(CheckPhoneNumberFragment.java:238) at com.firebase.ui.auth.ui.phone.CheckPhoneNumberFragment.onActivityCreated(CheckPhoneNumberFragment.java:127) at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2994) at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:559) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:262) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1797) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1715) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1658) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2780) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2715) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:262) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:478) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1455) at android.app.Activity.performStart(Activity.java:8076) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3653) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2203) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7822) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Expected Results:

  • Opening activity

Relevant Code:

I was opening activity with ActivityResultLauncher, but after this error tried different approach with PendingIntent but still crashes.

`final Intent phoneAuthIntent = AuthUI.getInstance() .createSignInIntentBuilder() .setAvailableProviders(providers) .setLogo(R.drawable.simplify_logo) .setTheme(R.style.FirebaseAuthTheme) .setTosAndPrivacyPolicyUrls( getResources().getString(R.string.terms_and_conditions_url), getResources().getString(R.string.privacy_url)) .setIsSmartLockEnabled(!BuildConfig.DEBUG /* credentials /, true / hints */) .build();

    PendingIntent pendingIntent = PendingIntent.getActivity(requireActivity().getApplicationContext(),
            123, phoneAuthIntent,
            /* flags */ PendingIntent.FLAG_IMMUTABLE);

    //binding.authenticationAcceptButton.setOnClickListener(button -> signInLauncher.launch(phoneAuthIntent));
    binding.authenticationAcceptButton.setOnClickListener(button -> {
        try {
            pendingIntent.send(123);
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }
    });`

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 20 (4 by maintainers)

Most upvoted comments

Basically two options:

  1. Look for where the PendingIntent is built, then find the library that adds this code and update to a version that supports Android 12.

    For the original reported crash the Intent is built here:

    at com.google.android.gms.internal.auth-api.zzr.zzc(com.google.android.gms:play-services-auth@@19.0.0:19
    at com.google.android.gms.auth.api.credentials.CredentialsClient.getHintPickerIntent(com.google.android.gms:play-services-auth@@19.0.0:10)
    

    So in that case it is enough to explicitly add a newer version of play-services-auth to your dependencies: implementation("com.google.android.gms:play-services-auth:20.0.1")

    If possible, test the sign-in flow on an Android 12 emulator or device to be sure.

  2. Do not target Android 12 (e.g. if not all your libraries that use PendingIntent are updated for Android 12).

updating dependencies (firebase-bom -> 29.0.3, play-services-auth -> 20.0.0, play:core -> 1.10.2) solved the problem for me

This should be fixed in version 8.0.2 of FirebaseUI for Android

@thatfiredev How is that a solution? That’s just a work-around. Your library should work out of the box, without needing to update any of its dependencies manually.

This is still happening with the firebase email sign-in, is there a proper workaround?

Thanks, @mikehardy. I found the issue. The developers of this module need to update their documentation

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.storyshots.android/com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity}: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

@zjamshidi your very error message gives you the clue to get you on the path. New Facebook SDKs have breaking changes in initialization sequence. You must adapt to them. Has nothing to do with this module + this issue

@haluzpav thanks for the call out! I’ve opened #2063 to fix that.

Closing this. See UweTrottmann’s comment for the general solution.