kotlin 以S+(版本31及更高版本)为目标要求在创建PendingIntent时指定FLAG_IMMUTABLE或FLAG_MUTABLE之一

uubf1zoe  于 2023-01-02  发布在  Kotlin
关注(0)|答案(1)|浏览(202)

我用Kotlin语。
我一直面对这个未决意图错误。

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.chugnchunon.chungchunon_android, PID: 20394
    java.lang.RuntimeException: Unable to create application com.chugnchunon.chungchunon_android.GlobalApplication: java.lang.IllegalArgumentException: com.chugnchunon.chungchunon_android: 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.ActivityThread.handleBindApplication(ActivityThread.java:6764)
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.IllegalArgumentException: com.chugnchunon.chungchunon_android: 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:401)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)
        at com.kakao.auth.Session.<init>(Session.java:156)
        at com.kakao.auth.Session.initialize(Session.java:101)
        at com.kakao.auth.KakaoSDK.init(KakaoSDK.java:101)
        at com.chugnchunon.chungchunon_android.GlobalApplication.onCreate(GlobalApplication.kt:17)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1277)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6759)
            ... 9 more

但当我在项目中搜索待定Intent时,我根本没有使用PendingIntent
此错误涉及GlobalApplication.kt:17
在全局应用程序中:
软件包com. chungchunon.chungchunon_安卓

import android.app.Application
import com.chugnchunon.chungchunon_android.Adapter.KakaoSDKAdapter
import com.kakao.auth.*

class GlobalApplication : Application() {
    companion object {
        var instance: GlobalApplication? = null
    }

    override fun onCreate() {
        super.onCreate()
        instance = this

        KakaoSDK.init(KakaoSDKAdapter(getAppContext()))
    }

    override fun onTerminate() {
        super.onTerminate()
        instance = null
    }

    fun getAppContext(): GlobalApplication {
        checkNotNull(instance) {
            "This Application does not inherit com.example.App"
        }
        return instance!!
    }
}

没有挂起意图。
有些人说要在build.gradle(:app)中设置以下依赖项

implementation 'androidx.work:work-runtime-ktx:2.7.0'

所以我做了,但我仍然有这个错误。
我该怎么补救呢?

3pmvbmvn

3pmvbmvn1#

Caused by: java.lang.IllegalArgumentException: com.chugnchunon.chungchunon_android: 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:401)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)
        at com.kakao.auth.Session.<init>(Session.java:156)
        at com.kakao.auth.Session.initialize(Session.java:101)
        at com.kakao.auth.KakaoSDK.init(KakaoSDK.java:101)
        at com.chugnchunon.chungchunon_android.GlobalApplication.onCreate(GlobalApplication.kt:17)

这里有两种可能性。
一个是您的应用程序是com.chugnchunon.chungchunon_android(参见堆栈跟踪代码段的最后一行)。如果是这样,则使用的是com.kakao.auth.KakaoSDK(请参阅堆栈跟踪片段倒数第二行),并且是它创建了损坏的PendingIntent。您需要更新您的应用,以使用包含该KakaoSDK类的库的更新版本,或联系其开发人员并指出问题。
另一个是com.chugnchunon.chungchunon_android.GlobalApplication本身来自一个库,* 它 * 使用的是KakaoSDK,在这种情况下,您需要升级到包含com.chugnchunon.chungchunon_android.GlobalApplication类的库的更新版本,或者联系它的开发人员并指出问题。

相关问题