我尝试使用TWA [https://developers.google.com/web/updates/2019/02/using-twa][1]
将pwa应用程序转换为android应用程序。
我遵循了所有步骤。当我单击Build并使用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。但是问题没有解决
答案 0 :(得分:3)
我遇到了同样的问题,问题似乎出在对androidx库的依赖以及最新版本的custom-tabs-client的依赖上。
事实证明,我们应该使用androidx.browser和android-browser-helper而不是custom-tabs-client
build.gradle:
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.github.GoogleChrome:android-browser-helper:ff8dfc4ed3d4133aacc837673c88d090d3628ec8'
答案 1 :(得分: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上均可使用。