4

I tried to convert my pwa app to android app using TWA [https://developers.google.com/web/updates/2019/02/using-twa][1] . I followed all the steps. When I click Build and run the app using android emulator it throughs error

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.

I check many resources [Android App Startup Crash - customtabs.CustomTabsSession.validateRelationship . But problem not solved

Sivakumar
  • 56
  • 1
  • 8

2 Answers2

4

I've experienced the same problem and the problem seems to be with dependencies towards androidx libraries together with the latest version of custom-tabs-client.

It turns out we should be using androidx.browser and android-browser-helper instead of custom-tabs-client

build.gradle:

implementation 'androidx.browser:browser:1.0.0'
implementation 'com.github.GoogleChrome:android-browser-helper:ff8dfc4ed3d4133aacc837673c88d090d3628ec8'
Tobias Harle
  • 149
  • 5
  • 1
    Do you have a source for this info? It changed the error, but I'm now seeing a different error related to the LauncherActivity: `Unable to instantiate activity ComponentInfo{io.bvh.layer/android.support.customtabs.trusted.LauncherActivity}: java.lang.ClassNotFoundException: Didn't find class "android.support.customtabs.trusted.LauncherActivity`. – Alex Sep 20 '19 at 18:41
  • Sure, I got it from here: https://bugs.chromium.org/p/chromium/issues/detail?id=983378 – Tobias Harle Sep 20 '19 at 19:07
  • 3
    @Alex You should probably use com.google.androidbrowserhelper.trusted.LauncherActivity instead. – Tobias Harle Sep 20 '19 at 19:24
  • Ah, got it. Thanks for the info. – Alex Sep 20 '19 at 19:49
1

I realise that there are so many variants that this will be hit or miss, but here's what I put in 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'}

The same error went away with the above. Worked on Android 4.4 and on Android 9.

Andrew Jens
  • 1,032
  • 15
  • 16