英文:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE. App crashes due to this
问题
崩溃日志 -
--------- 崩溃开始
2023-03-03 15:33:10.259 11639-12705/AndroidRuntime: 严重异常: AsyncTask #1
进程: PID: 11639
java.lang.RuntimeException: 在执行doInBackground()时发生错误
at android.os.AsyncTask$4.done(AsyncTask.java:415)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)
at java.util.concurrent.FutureTask.setException(FutureTask.java:250)
at java.util.concurrent.FutureTask.run(FutureTask.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.IllegalArgumentException: 针对S+(版本31及以上),在创建PendingIntent时,要求指定FLAG_IMMUTABLE或FLAG_MUTABLE之一。
强烈建议使用FLAG_IMMUTABLE,仅在PendingIntent需要与内联回复或气泡一起使用时才使用FLAG_MUTABLE。
at android.app.PendingIntent.checkFlags(PendingIntent.java:402)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:672)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:659)
at com.google.android.gms.gcm.zzm.<init>(Unknown Source:17)
at com.google.android.gms.gcm.GcmNetworkManager.zzd(Unknown Source:28)
at com.google.android.gms.gcm.GcmNetworkManager.schedule(Unknown Source:8)
at com.quickblox.messages.services.SubscribeTaskManager.a(Unknown Source:58)
at com.quickblox.messages.services.SubscribeService.c(Unknown Source:24)
at com.quickblox.messages.services.SubscribeService.a(Unknown Source:150)
at com.quickblox.messages.services.SubscribeService.a(Unknown Source:136)
at com.quickblox.messages.services.SubscribeService.e(Unknown Source:12)
at com.quickblox.messages.services.SubscribeService.b(Unknown Source:18)
at com.quickblox.messages.services.SubscribeService.onHandleWork(Unknown Source:51)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:396)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:387)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
... 3 more
2023-03-03 15:33:10.263 1768-2337/? E/OplusNetworkStackManager: 回调长度 = 6
根build.gradle -
buildscript {
ext.kotlin_version = '1.8.0'
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven {
url 'https://maven.fabric.io/public'
}
maven {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
classpath 'io.fabric.tools:gradle:1.28.0'
}
}
所有项目 {
repositories {
flatDir {
dirs 'libs'
}
google()
jcenter()
maven { url 'https://jitpack.io' }
maven {
url 'https://maven.google.com/'
}
maven {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
}
任务清理(类型:删除){
删除 rootProject.buildDir
}
app:build.gradle -
应用插件: 'com.android.application'
应用插件: 'kotlin-android'
android {
compileSdkVersion 33
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding false
}
lintOptions {
checkReleaseBuilds false
}
defaultConfig {
applicationId ""
minSdkVersion 20
targetSdkVersion 31
versionCode 109
versionName "1.0.6"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
project.configurations.all {
resolutionStrategy {
force 'androidx.work:work-runtime-ktx:2.8.0'
}
}
}
repositories {
maven {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
crunchPngs false // or true
}
}
}
//def qbSdkVersion = '3.7.0'
def work_version = "2.8.0"
依赖关系 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
// implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.multidex:multidex:2.0.0'
// implementation "com.google.android.gms:play-services-base:16.1.0"
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.google.android.gms:play-services-base:18.2.0'
constraints {
implementation('androidx.work:work-runtime:2.8.0') {
because 'play-services-ads依赖于work-runtime:2.1.0,与targetSdk 31不
<details>
<summary>英文:</summary>
Crash log -
--------- beginning of crash
2023-03-03 15:33:10.259 11639-12705/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: PID: 11639
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:415)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)
at java.util.concurrent.FutureTask.setException(FutureTask.java:250)
at java.util.concurrent.FutureTask.run(FutureTask.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.IllegalArgumentException: 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:402)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:672)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:659)
at com.google.android.gms.gcm.zzm.<init>(Unknown Source:17)
at com.google.android.gms.gcm.GcmNetworkManager.zzd(Unknown Source:28)
at com.google.android.gms.gcm.GcmNetworkManager.schedule(Unknown Source:8)
at com.quickblox.messages.services.SubscribeTaskManager.a(Unknown Source:58)
at com.quickblox.messages.services.SubscribeService.c(Unknown Source:24)
at com.quickblox.messages.services.SubscribeService.a(Unknown Source:150)
at com.quickblox.messages.services.SubscribeService.a(Unknown Source:136)
at com.quickblox.messages.services.SubscribeService.e(Unknown Source:12)
at com.quickblox.messages.services.SubscribeService.b(Unknown Source:18)
at com.quickblox.messages.services.SubscribeService.onHandleWork(Unknown Source:51)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:396)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:387)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
... 3 more
2023-03-03 15:33:10.263 1768-2337/? E/OplusNetworkStackManager: callback len = 6
Root build.gradle -
buildscript {
ext.kotlin_version = '1.8.0'
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven {
url 'https://maven.fabric.io/public'
}
maven {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
classpath 'io.fabric.tools:gradle:1.28.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
google()
jcenter()
maven { url 'https://jitpack.io' }
maven {
url 'https://maven.google.com/'
}
maven {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app:build.gradle -
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
//apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 33
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding false
}
lintOptions {
checkReleaseBuilds false
}
defaultConfig {
applicationId ""
minSdkVersion 20
targetSdkVersion 31
versionCode 109
versionName "1.0.6"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
project.configurations.all {
resolutionStrategy {
force 'androidx.work:work-runtime-ktx:2.8.0'
}
}
}
repositories {
maven {
url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
crunchPngs false // or true
}
}
}
//def qbSdkVersion = '3.7.0'
def work_version = "2.8.0"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
// implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.multidex:multidex:2.0.0'
// implementation "com.google.android.gms:play-services-base:16.1.0"
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.google.android.gms:play-services-base:18.2.0'
constraints {
implementation('androidx.work:work-runtime:2.8.0') {
because 'play-services-ads depends on work-runtime:2.1.0 which is not compatible with targetSdk 31, but work-runtime:2.7.0 is'
}
}
implementation "com.google.android.gms:play-services-analytics:18.0.1"
constraints {
implementation('androidx.work:work-runtime:2.8.0') {
because 'play-services-ads depends on work-runtime:2.1.0 which is not compatible with targetSdk 31, but work-runtime:2.7.0 is'
}
}
implementation 'com.google.android.gms:play-services-wallet:19.1.0'
constraints {
implementation('androidx.work:work-runtime:2.8.0') {
because 'play-services-ads depends on work-runtime:2.1.0 which is not compatible with targetSdk 31, but work-runtime:2.7.0 is'
}
}
implementation 'androidx.appcompat:appcompat:1.7.0-alpha02'
implementation 'androidx.slice:slice-core:1.1.0-alpha02'
implementation 'androidx.slice:slice-builders:1.1.0-alpha02'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp:okhttp:2.2.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
implementation 'com.squareup.picasso:picasso:2.4.0'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
implementation "com.quickblox:quickblox-android-sdk-chat:3.9.2"
//include only necessary module dependency, all transitive modules will be included automatically
implementation "com.quickblox:quickblox-android-sdk-content:3.9.2"
implementation "com.quickblox:quickblox-android-sdk-messages:3.9.2"
implementation "com.quickblox:quickblox-android-sdk-customobjects:3.9.2"
implementation "com.quickblox:quickblox-android-sdk-core:3.9.2"
implementation "com.quickblox:quickblox-android-sdk-videochat-webrtc:3.9.2"
implementation "com.quickblox:quickblox-android-sdk-conference:3.9.2"
implementation 'com.mikhaellopez:circularimageview:3.2.0'
implementation 'com.github.stfalcon:chatkit:0.3.1'
implementation 'com.applandeo:material-calendar-view:1.5.1'
implementation 'com.braintreepayments:card-form:3.4.1'
implementation 'com.hlab.fabrevealmenu:fab-reveal-menu:1.0.3'
implementation 'com.github.arthurghazaryan:floatingactionmenu:1.0.0'
implementation 'com.labo.kaji:relativepopupwindow:0.3.1'
implementation 'com.github.douglasjunior:android-simple-tooltip:0.2.2'
implementation 'am.appwise.components:NoInternetDialog:1.1.3'
// implementation platform('com.google.firebase:firebase-bom')
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-messaging:23.1.1'
implementation 'com.google.firebase:firebase-crashlytics:18.3.5'
implementation('com.google.firebase:firebase-iid:21.1.0')
// implementation platform('com.google.firebase:firebase-bom:31.1.0')
// implementation 'com.github.prolificinteractive:material-calendarview:2.0.0'
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
implementation 'com.github.Kyash:android-target-instructions:0.1.4'
// implementation(name: 'sinch-android-rtc', version: '+', ext: 'aar')
implementation 'io.branch.sdk.android:library:3.+'
implementation 'com.github.joielechong:countrycodepicker:2.4.1'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'es.voghdev.pdfviewpager:library:1.1.2'
implementation 'com.bogdwellers:pinchtozoom:0.1'
implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
implementation 'org.webrtc:google-webrtc:1.0.22171'
implementation 'com.payumoney.sdkui:plug-n-play:1.6.1'
implementation 'com.google.android.play:core:1.10.3'
implementation 'com.github.javiersantos:BottomDialogs:1.2.1'
implementation 'com.github.jineshfrancs:CaptchaImageView:1.0'
implementation 'com.poovam:pin-edittext-field:1.2.3'
def billing_version = '5.1.0'
implementation "com.android.billingclient:billing:$billing_version"
implementation 'me.zhanghai.android.materialratingbar:library:1.4.0'
implementation 'com.github.angads25:toggle:1.1.0'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'info.guardianproject.netcipher:netcipher:2.1.0'
// implementation 'androidx.work:work-runtime:2.8.0'
// implementation 'androidx.work:work-runtime-ktx:2.8.0'
// implementation("androidx.work:work-runtime:2.8.0")
// (Java only)
implementation("androidx.work:work-runtime:$work_version")
// Kotlin + coroutines
implementation("androidx.work:work-runtime-ktx:$work_version")
// optional - RxJava2 support
implementation("androidx.work:work-rxjava2:$work_version")
// optional - GCMNetworkManager support
implementation("androidx.work:work-gcm:$work_version")
// optional - Test helpers
androidTestImplementation("androidx.work:work-testing:$work_version")
// optional - Multiprocess support
implementation "androidx.work:work-multiprocess:$work_version"
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
MyFirebaseMessagingService has PendingIntent as follows -
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE );
I was trying to upload new version to play store, it ask me to use sdk 31 to upload new version. After setting up sdk 31 then this pending intent crash is introduced. I have tried to add Work-runtime is not resolving the problem. App is crashing at random times with the same error message.
</details>
# 答案1
**得分**: 0
`PendingIntent.FLAG_IMMUTABLE`需要API级别23。
由于您的`minSdkVersion`为20,您应该进行SDK检查
```java
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_CANCEL_CURRENT);
英文:
PendingIntent.FLAG_IMMUTABLE
requires API level 23
Since your minSdkVersion
is 20, you should perform the sdk check
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_CANCEL_CURRENT);
</details>
# 答案2
**得分**: 0
你应该将minSDK更新到23,并使用以下代码来处理PendingIntent:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE || PendingIntent.FLAG_UPDATE_CURRENT)
这对我有用。
<details>
<summary>英文:</summary>
You should update minSDK to 23 and use following code for PendingIntent :
PendingIntent pendingIntent = PendingIntent.getActivity( this, 0, intent, PendingIntent.FLAG_IMMUTABLE || PendingIntent.FLAG_UPDATE_CURRENT)
This worked for me.
</details>
# 答案3
**得分**: 0
这花费了我很多时间来找出是哪个库造成的问题。在我的情况下,是QuickBlox。我已将QuickBlox更新到4.0.3,并使用work-runtime 2.7.1。
现在我的Build.gradle文件有以下更改 -
implementation ("com.quickblox:quickblox-android-sdk-content:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-messages:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-customobjects:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-core:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-conference:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-videochat-webrtc:4.0.3")
implementation 'androidx.work:work-runtime:2.7.1'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
崩溃问题已解决。尽管我将不得不重新调整QuickBlox的功能,因为他们在更新的库中进行了一些更改。感谢每个尝试帮助我的人。
<details>
<summary>英文:</summary>
It cost me a lot of time to figure out which library was culprit. It was QuickBlox in my case. I have updated QuickBlox to 4.0.3 and using work-runtime 2.7.1
Now my Build.gradle have following changes -
implementation ("com.quickblox:quickblox-android-sdk-content:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-messages:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-customobjects:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-core:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-conference:4.0.3")
implementation ("com.quickblox:quickblox-android-sdk-videochat-webrtc:4.0.3")
implementation 'androidx.work:work-runtime:2.7.1'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
Crash is gone. Although I will have to rework on QuickBlox functionality as they have changed few things with updated library. Thank you everyone who tried to help.
</details>
# 答案4
**得分**: 0
```plaintext
现在 Build.gradle 文件有以下更改:
// (仅限 Java)
implementation("androidx.work:work-runtime:2.8.1")
// Kotlin + 协程
implementation("androidx.work:work-runtime-ktx:2.8.1")
// 可选 - RxJava2 支持
implementation("androidx.work:work-rxjava2:2.8.1")
注意:如果您使用 Firebase AdMob 或与 Firebase 相关的其他库,则请更新版本
implementation 'com.google.android.gms:play-services-analytics:18.0.2'
implementation 'com.google.android.gms:play-services-ads:22.1.0'
implementation 'com.google.firebase:firebase-messaging:23.1.2'
英文:
Now Build.gradle have following changes -
// (Java only)
implementation("androidx.work:work-runtime:2.8.1")
// Kotlin + coroutines
implementation("androidx.work:work-runtime-ktx:2.8.1")
// optional - RxJava2 support
implementation("androidx.work:work-rxjava2:2.8.1")
Note: If you use Firebase admob or another library related to Firebase then update the version
implementation 'com.google.android.gms:play-services-analytics:18.0.2'
implementation 'com.google.android.gms:play-services-ads:22.1.0'
implementation 'com.google.firebase:firebase-messaging:23.1.2'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论