1

最近我们正在为Android 12做准备,我们将compileSdkVersion和targetSdkVersion更新到31更新到31后,TWA无法启动。给出的错误是

    java.lang.IllegalArgumentException: xxx.twa: 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 androidx.browser.customtabs.CustomTabsClient.createSessionId(CustomTabsClient.java:231)
        at androidx.browser.customtabs.CustomTabsClient.newSession(CustomTabsClient.java:269)
        at com.google.androidbrowserhelper.trusted.TwaLauncher$TwaCustomTabsServiceConnection.onCustomTabsServiceConnected(TwaLauncher.java:324)
        at androidx.browser.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:57)
        at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2077)
        at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2110)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        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:1003)

更新 androidx.browser:browser 后implementation 'androidx.browser:browser:1.4.0-beta01'出现以下错误

    java.lang.IllegalArgumentException: xxx.twa: 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.androidbrowserhelper.trusted.FocusActivity.addToIntent(FocusActivity.java:43)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.launchWhenSplashScreenReady(TwaLauncher.java:272)
        at com.google.androidbrowserhelper.trusted.TwaLauncher.lambda$launchWhenSessionEstablished$4$TwaLauncher(TwaLauncher.java:257)
        at com.google.androidbrowserhelper.trusted.-$$Lambda$TwaLauncher$6zo6viK_vVSs4bt2THXs48ruews.run(Unknown Source:6)
        at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.lambda$onSplashImageTransferred$1$PwaWrapperSplashScreenStrategy(PwaWrapperSplashScreenStrategy.java:208)
        at com.google.androidbrowserhelper.trusted.splashscreens.-$$Lambda$PwaWrapperSplashScreenStrategy$p-f_rUE4TsZEGw17K3MBDrUxlsQ.run(Unknown Source:4)
        at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.runWhenEnterAnimationComplete(PwaWrapperSplashScreenStrategy.java:215)
        at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.onSplashImageTransferred(PwaWrapperSplashScreenStrategy.java:207)
        at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.lambda$configureTwaBuilder$0$PwaWrapperSplashScreenStrategy(PwaWrapperSplashScreenStrategy.java:195)
        at com.google.androidbrowserhelper.trusted.splashscreens.-$$Lambda$PwaWrapperSplashScreenStrategy$AEuRt7oVnGOP2vf-Uvl2RaqkFW4.onFinished(Unknown Source:6)
        at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute(SplashImageTransferTask.java:144)
        at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute(SplashImageTransferTask.java:91)
        at android.os.AsyncTask.finish(AsyncTask.java:771)
        at android.os.AsyncTask.access$900(AsyncTask.java:199)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
        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:7842)
        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:1003)

我试图找到 com.google.androidbrowserhelper 的更新版本,但找不到任何内容。我目前正在使用implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.2'

有没有人遇到这种情况并能够提供帮助?

4

1 回答 1

0

这是一个已知问题,需要对底层androidx.browser库进行更改。更改在 中1.4.0-rc1,在接下来的几周内应该会保持稳定。需要进行另一项更改android-browser-helper,一旦更改androidx.browser完成,我们将发布一个可与 targetSdk 31 良好配合的更新。

您可以使用 android.browser 的 release-candidate 版本并构建您自己的 android-browser-helper,但我建议等待生产版本升级到目标 SDK 31。

于 2021-10-21T08:30:15.067 回答