Android API 31 FLAG_IMMUTABLE 使用 Firebase 身份验证时出错 UI

Android API 31 FLAG_IMMUTABLE Error using Firebase Auth UI

在 Firebase Auth UI 库期间,我在 API 31 台设备中收到以下错误(仅 Phone 数字凭据),

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)

下面是我的 gradle 个文件,

应用级别:

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: "androidx.navigation.safeargs.kotlin"

apply plugin: 'com.google.firebase.firebase-perf'

def versionMajor = 2
def versionMinor = 0
def versionPatch = 10


android {
   
    compileSdkVersion 31
    buildToolsVersion "30.0.3"
    defaultConfig {
        applicationId "com.aaa.xxxx"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch

        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_1_8.toString()
        }

        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas".toString())
                arg("room.incremental", "true")
                arg("room.expandProjection", "true")
            }
        }
    }
    buildTypes {

        debug {
            minifyEnabled false
            multiDexEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            manifestPlaceholders = [enableCrashReporting: "false"]
        }
    }

    // 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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
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 "androidx.coordinatorlayout:coordinatorlayout:1.1.0"


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 "androidx.navigation:navigation-fragment-ktx:2.3.5"
implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
implementation "androidx.fragment:fragment-ktx:1.4.0"

// LifeCycle
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.0"

// Circle Image View
implementation 'de.hdodenhof:circleimageview:3.1.0'

implementation "androidx.recyclerview:recyclerview:1.2.1"
// 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 "org.jetbrains.kotlin:kotlin-stdlib:1.5.31"

//Zoom
implementation 'com.github.chrisbanes:PhotoView:2.3.0'

//Room
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"

// json
implementation 'com.google.code.gson:gson:2.8.9'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.13.0"

// SDP
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'

// Security
implementation "androidx.security:security-crypto:1.1.0-alpha03"

// Animation
implementation 'com.airbnb.android:lottie:4.2.2'

// Browser
implementation "androidx.browser:browser:1.4.0"

// Camera
def camerax_version = "1.0.2"
// CameraX core library using camera2 implementation
implementation "androidx.camera:camera-camera2:$camerax_version"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:$camerax_version"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha31"

implementation "com.github.lisawray.groupie:groupie:2.9.0"

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'

}

项目级别,

// 顶级构建文件,您可以在其中添加所有 sub-projects/modules.

通用的配置选项
buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.firebase:perf-plugin:1.4.0'
        def nav_version = "2.3.5"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

我在网上搜索过,有些问题是通过添加 androidx.work:work-runtime-ktx:2.7.1 pacakage 解决的,但就我而言,即使这样也没有解决。

任何人都可以帮助解决这个问题。

就我而言,firebase UI (com.firebaseui:firebase-ui-auth:8.0.0) 使用的是 com.google.android.gms:play-services-auth: 19.0.0 我用命令 './gradlew -q app:dependencyInsight --dependency play-services-auth --configuration debugCompileClasspath'

找到了

这个版本的 play services auth 导致了我的问题。

我单独添加了一个

实施'com.google.android.gms:play-services-auth:20.0.1'

我的gradle,这个问题消失了。