3

我尝试使用 TWA 将我的 pwa 应用程序转换为 android 应用程序[https://developers.google.com/web/updates/2019/02/using-twa][1]。我遵循了所有步骤。当我单击构建并使用 android 模拟器运行应用程序时,它会出现错误

2019-09-18 15:38:31.942 6870-6870/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.pwa.vayup, PID: 6870
    java.lang.IllegalAccessError: Method 'android.os.Bundle android.support.customtabs.CustomTabColorSchemeParams.toBundle()' is inaccessible to class 'androidx.browser.customtabs.CustomTabsIntent$Builder' (declaration of 'androidx.browser.customtabs.CustomTabsIntent$Builder' appears in /data/app/com.pwa.vayup-2/base.apk)
        at androidx.browser.customtabs.CustomTabsIntent$Builder.build(CustomTabsIntent.java:746)
        at android.support.customtabs.trusted.TrustedWebActivityIntentBuilder.buildCustomTabsIntent(TrustedWebActivityIntentBuilder.java:162)
        at android.support.customtabs.trusted.TwaLauncher.launchCct(TwaLauncher.java:135)
        at android.support.customtabs.trusted.TwaLauncher.launch(TwaLauncher.java:127)
        at android.support.customtabs.trusted.LauncherActivity.onCreate(LauncherActivity.java:134)
        at android.app.Activity.performCreate(Activity.java:6662)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
2019-09-18 15:38:31.944 1599-2084/? W/ActivityManager:   Force finishing activity com.

我检查了许多资源 [ Android App Startup Crash - customtabs.CustomTabsSession.validateRelationship。但是问题没有解决

4

2 回答 2

4

我遇到了同样的问题,问题似乎在于对 androidx 库的依赖以及最新版本的 custom-tabs-client。

事实证明我们应该使用 androidx.browser 和android-browser-helper而不是 custom-tabs-client

构建.gradle:

implementation 'androidx.browser:browser:1.0.0'
implementation 'com.github.GoogleChrome:android-browser-helper:ff8dfc4ed3d4133aacc837673c88d090d3628ec8'
于 2019-09-20T10:38:08.810 回答
1

我意识到有很多变体,这会被击中或错过,但这是我在 build.gradle 中放入的内容:

dependencies {

// From a combination of:
//  https://medium.com/@elliatab/trusted-web-activities-for-android-developers-4d8dea3dac9a
// and
//  https://developers.google.com/web/updates/2019/02/using-twa

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//implementation 'com.android.support:design:28.0.0'

implementation 'com.github.GoogleChrome:custom-tabs-client:7ab7178ae0c4858d15b1918bded4dd5cac758870'

testImplementation 'junit:junit:4.12'}

上述相同的错误消失了。适用于 Android 4.4 和 Android 9。

于 2019-11-06T04:45:58.270 回答