title: Android API 31 FLAG_IMMUTABLE Error using Firebase Auth UI
body: <p>I'm receving the below error in API 31 devices during Firebase Auth UI library(Only Phone number credential),</p>
  <pre><code>Fatal Exception: java.lang.IllegalArgumentException: com.sstech.racemanager: 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(zzr.java:19)
         at com.google.android.gms.auth.api.credentials.CredentialsClient.getHintPickerIntent(CredentialsClient.java: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:2996)
         at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:580)
         at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:285)
         at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
         at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
         at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
         at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
         at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
         at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
         at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
         at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1455)
         at android.app.Activity.performStart(Activity.java:8339)
         at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3925)
         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:2407)
         at android.os.Handler.dispatchMessage(Handler.java:106)
         at android.os.Looper.loopOnce(Looper.java:233)
         at android.os.Looper.loop(Looper.java:334)
         at android.app.ActivityThread.main(ActivityThread.java:8278)
         at java.lang.reflect.Method.invoke(Method.java)
         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1065)
  </code></pre>
  <p>Below is my gradle files,</p>
  <p>app Level:</p>
  <pre><code>plugins {
      id 'com.android.application'
      id 'kotlin-android'
      id 'kotlin-kapt'
      id 'com.google.gms.google-services'
      id 'com.google.firebase.crashlytics'
      id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
  }
  
  
  apply plugin: 'kotlin-android-extensions'
  
  apply plugin: &quot;androidx.navigation.safeargs.kotlin&quot;
  
  apply plugin: 'com.google.firebase.firebase-perf'
  
  def versionMajor = 2
  def versionMinor = 0
  def versionPatch = 10
  
  
  android {
     
      compileSdkVersion 31
      buildToolsVersion &quot;30.0.3&quot;
      defaultConfig {
          applicationId &quot;com.aaa.xxxx&quot;
          minSdkVersion 21
          targetSdkVersion 31
          versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
  
          versionName &quot;${versionMajor}.${versionMinor}.${versionPatch}&quot;
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
  
          kotlinOptions {
              jvmTarget = JavaVersion.VERSION_1_8.toString()
          }
  
          kapt {
              arguments {
                  arg(&quot;room.schemaLocation&quot;, &quot;$projectDir/schemas&quot;.toString())
                  arg(&quot;room.incremental&quot;, &quot;true&quot;)
                  arg(&quot;room.expandProjection&quot;, &quot;true&quot;)
              }
          }
      }
      buildTypes {
  
          debug {
              minifyEnabled false
              multiDexEnabled true
              shrinkResources false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
              manifestPlaceholders = [enableCrashReporting: &quot;false&quot;]
          }
      }
  
      // Enables data binding.
      buildFeatures {
          dataBinding = true
      }
      compileOptions {
          sourceCompatibility = 1.7
      }
      // For Java issue
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
      }
  
  }
  
  dependencies {
  
  implementation &quot;org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version&quot;
  implementation 'androidx.appcompat:appcompat:1.4.0'
  implementation 'androidx.core:core-ktx:1.7.0'
  implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'com.google.android.material:material:1.4.0'
  implementation 'com.google.android.play:core-ktx:1.8.1'
  implementation 'com.google.firebase:firebase-perf:20.0.4'
  implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
  implementation 'com.google.android.gms:play-services-maps:18.0.1'
  implementation 'androidx.preference:preference:1.1.1'
  implementation &quot;androidx.coordinatorlayout:coordinatorlayout:1.1.0&quot;
  
  
  testImplementation 'junit:junit:4.13'
  androidTestImplementation 'androidx.test.ext:junit:1.1.2'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
  implementation 'androidx.arch.core:core-runtime:2.1.0'
  
  // Firebase
  implementation platform('com.google.firebase:firebase-bom:29.0.3')
  implementation 'com.google.firebase:firebase-auth-ktx'
  implementation 'com.google.firebase:firebase-storage-ktx'
  implementation 'com.google.firebase:firebase-database-ktx'
  implementation 'com.google.firebase:firebase-config-ktx'
  implementation 'com.google.firebase:firebase-inappmessaging-display-ktx'
  implementation 'com.google.firebase:firebase-messaging-ktx'
  implementation 'com.google.firebase:firebase-analytics-ktx'
  implementation 'com.google.firebase:firebase-crashlytics'
  implementation 'com.google.firebase:firebase-dynamic-links'
  implementation 'com.google.firebase:firebase-functions'
  implementation 'com.google.firebase:firebase-firestore-ktx'
  implementation 'com.firebaseui:firebase-ui-auth:8.0.0'
  
  // Fragment
  implementation &quot;androidx.navigation:navigation-fragment-ktx:2.3.5&quot;
  implementation &quot;androidx.navigation:navigation-ui-ktx:2.3.5&quot;
  implementation &quot;androidx.fragment:fragment-ktx:1.4.0&quot;
  
  // LifeCycle
  implementation &quot;androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0&quot;
  implementation &quot;androidx.lifecycle:lifecycle-extensions:2.2.0&quot;
  implementation &quot;androidx.lifecycle:lifecycle-common-java8:2.4.0&quot;
  
  // Circle Image View
  implementation 'de.hdodenhof:circleimageview:3.1.0'
  
  implementation &quot;androidx.recyclerview:recyclerview:1.2.1&quot;
  // For control over item selection of both touch and mouse driven selection
  
  // Image cache
  implementation 'com.github.bumptech.glide:glide:4.12.0'
  kapt 'com.github.bumptech.glide:compiler:4.12.0'
  
  //gmap
  implementation 'com.google.android.gms:play-services-location:19.0.0'
  
  // compressor
  implementation 'id.zelory:compressor:3.0.1'
  implementation 'com.github.Shouheng88:compressor:1.5.0'
  
  
  // kotlin general
  implementation &quot;org.jetbrains.kotlin:kotlin-stdlib:1.5.31&quot;
  
  //Zoom
  implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  
  //Room
  implementation &quot;androidx.room:room-runtime:2.3.0&quot;
  kapt &quot;androidx.room:room-compiler:2.3.0&quot;
  implementation &quot;androidx.room:room-ktx:2.3.0&quot;
  
  // json
  implementation 'com.google.code.gson:gson:2.8.9'
  implementation &quot;com.fasterxml.jackson.module:jackson-module-kotlin:2.13.0&quot;
  
  // SDP
  implementation 'com.intuit.sdp:sdp-android:1.0.6'
  implementation 'com.intuit.ssp:ssp-android:1.0.6'
  
  // Security
  implementation &quot;androidx.security:security-crypto:1.1.0-alpha03&quot;
  
  // Animation
  implementation 'com.airbnb.android:lottie:4.2.2'
  
  // Browser
  implementation &quot;androidx.browser:browser:1.4.0&quot;
  
  // Camera
  def camerax_version = &quot;1.0.2&quot;
  // CameraX core library using camera2 implementation
  implementation &quot;androidx.camera:camera-camera2:$camerax_version&quot;
  // CameraX Lifecycle Library
  implementation &quot;androidx.camera:camera-lifecycle:$camerax_version&quot;
  // CameraX View class
  implementation &quot;androidx.camera:camera-view:1.0.0-alpha31&quot;
  
  implementation &quot;com.github.lisawray.groupie:groupie:2.9.0&quot;
  
  implementation 'com.github.dhaval2404:imagepicker:2.1'
  
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
  implementation 'androidx.work:work-runtime-ktx:2.7.1'
  
  }
  </code></pre>
  <p>Project level,</p>
  <p>// Top-level build file where you can add configuration options common to all sub-projects/modules.</p>
  <pre><code>buildscript {
      ext.kotlin_version = '1.6.10'
      repositories {
          google()
          mavenCentral()
      }
      dependencies {
          classpath 'com.google.firebase:perf-plugin:1.4.0'
          def nav_version = &quot;2.3.5&quot;
          classpath &quot;androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version&quot;
          classpath 'com.android.tools.build:gradle:7.0.4'
          classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version&quot;
          classpath 'com.google.gms:google-services:4.3.10'
          classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
          classpath &quot;com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0&quot;
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>
  <p>I've searched online and for some the issue is resolved by adding androidx.work:work-runtime-ktx:2.7.1 pacakage, but in my case even this is not solving.</p>
  <p>Can anyone help on this issue.</p>