You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Android SDK 31后应用启动崩溃 出现PendingIntent及登录按钮加载错误

补充说明

我移除了Appodeal、explorestack:consent和jcenter后问题解决。Appodeal需要依赖已废弃的jcenter才能正常构建,我暂不确定具体问题根源,但问题肯定出自上述三个依赖/配置项之一。

问题描述

我近期更新了build.gradle中的依赖库以及targetSdkVersion,完成测试后上传至Google Play,突然收到崩溃上报,两类报错信息如下:

报错1:Android 12+ PendingIntent适配错误

Fatal Exception: java.lang.IllegalArgumentException: com.name.app: 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.getBroadcastAsUser(PendingIntent.java:645)
       at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
       at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174)
       at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
       at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
       at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:920)

报错2:Google登录按钮加载失败

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.name.app/com.name.app.Activities.LoginActivity}: android.view.InflateException: Binary XML file line #29: Error inflating class com.google.android.gms.common.SignInButton
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2330)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
       at android.app.ActivityThread.access$800(ActivityThread.java:156)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5314)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:374)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我的业务代码没有使用PendingIntent,该问题大概率是引入的第三方依赖导致;另外谷歌登录按钮此前一直可以正常使用,没有出现过报错。

相关配置文件

App模块build.gradle

apply plugin: 'com.android.application'
// Apply the Google Services plugin (if it's not there already).
apply plugin: 'com.google.gms.google-services'
// Add the Firebase Crashlytics plugin.
apply plugin: 'com.google.firebase.crashlytics'
android {
    signingConfigs {
        config {
            
        }
    }
    compileSdkVersion 31
    defaultConfig {
        applicationId "com.name.app"
        minSdkVersion 21
        targetSdkVersion 31

        versionCode 91
        versionName "91"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    buildToolsVersion "30.0.3"
}

repositories {
    maven { url "https://artifactory.appodeal.com/appodeal" }
    google()
    mavenCentral()
    jcenter()
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.media:media:1.4.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.browser:browser:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'com.google.android.material:material:1.5.0-alpha05'

    implementation 'androidx.activity:activity:1.4.0'

    implementation 'com.jjoe64:graphview:4.2.2'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-core:20.0.0'
    implementation 'com.google.firebase:firebase-database:20.0.2'
    implementation 'com.google.android.gms:play-services-auth:19.2.0'

    implementation 'com.android.billingclient:billing:4.0.0'
    implementation 'com.google.firebase:firebase-crashlytics:18.2.4'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    testImplementation 'junit:junit:4.13.2'
    implementation 'com.google.android.ump:user-messaging-platform:2.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'

    implementation 'com.explorestack:consent:1.0.4'
    implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0'

    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation('com.appodeal.ads:sdk:2.10.2.+') {
        exclude group: 'com.appodeal.ads.sdk.networks', module: 'amazon_ads'
        exclude group: 'com.appodeal.ads.sdk.networks', module: 'appodeal'
        exclude group: 'com.appodeal.ads.sdk.networks', module: 'nast'
    }
}

项目级build.gradle

buildscript {
    
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url "https://maven.google.com"
        }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

LoginActivity AndroidManifest配置

崩溃出现在启动页LoginActivity,对应配置如下:

<activity
    android:name=".LoginActivity"
    android:label="Name"
    android:exported="true"
    android:configChanges="orientation"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
       <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />

       <data
           android:scheme="http"
           android:host="name.com" />
    </intent-filter>
</activity>

有没有人遇到过类似的问题?我本地一直无法复现该故障。


内容的提问来源于stack exchange,提问作者El_Loco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 00:06:05