Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_IMMUTABLE be specified when creating a Pendingintent

1.5k Views Asked by At

I am facing this issue while upgrading the targetSDK to 31 (Android 12)

I am using react native, A package called react-native-sms-retriver There is a PendingIntent used in PhoneNumberHelper.java

        final GoogleApiClient googleApiClient = getGoogleApiClient(context);

        final PendingIntent intent = Auth.CredentialsApi
                .getHintPickerIntent(googleApiClient, request);

        try {
            activity.startIntentSenderForResult(intent.getIntentSender(),
                    REQUEST_PHONE_NUMBER_REQUEST_CODE, null, 0, 0, 0);
        } catch (IntentSender.SendIntentException e) {
            promiseReject(SEND_INTENT_ERROR_TYPE, SEND_INTENT_ERROR_MESSAGE);
            callAndResetListener();
        } finally {
            if (googleApiClient.isConnected()) {
                googleApiClient.disconnect();
            }
        }

How can i fix this?

I have tried the following to no avail

  1. adding implementation 'androidx.work:work-runtime:2.7.1' in android/build.gragle
  2. adding implementation 'com.google.android.gms:play-services-base:18.1.0' implementation 'com.google.android.gms:play-services-basement:18.1.0' in app/build.gradle

I have seen the following code in similar questions but not sure how to use it in my case

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             return PendingIntent.getActivity(context, id, intent, PendingIntent.FLAG_IMMUTABLE | flag);
         } else {
             return PendingIntent.getActivity(context, id, intent, flag);
         }

I am not sure how to use it since there is no PendingIntent.getActivity() in the packages code.

Error Screenshot

1

There are 1 best solutions below

0
Amit Yadav On

The issue is because of the auth library is not having the latest SDK version (31) requirements. I had a similar issue and it got fixed after updating the latest auth library in build Gradle.

Update your auth library version to The issue is because of the auth library is not having the latest SDK version (31) requirements. I had a similar issue and it got fixed after updating the latest auth library in build Gradle.

Update your auth library version to 20.7.0 or later version

implementation "com.google.android.gms:play-services-auth:20.7.0" or later version

implementation "com.google.android.gms:play-services-auth:20.7.0"