简体   繁体   English

Android App Startup Crash - customtabs.CustomTabsSession.validateRelationship

[英]Android App Startup Crash - customtabs.CustomTabsSession.validateRelationship

I followed Googles guidelines for the recent Trusted Web Activities and my app has been working fine on my device and some select emulators. 我遵循谷歌最近的可信网络活动指南 ,我的应用程序在我的设备和一些选择模拟器上工作正常。

However, on certain devices and emulators (such as Google Pixel 2) I get an immediate crash on startup. 但是,在某些设备和模拟器(例如Google Pixel 2)上,我在启动时立即崩溃。

The logcat outputs: logcat输出:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ocdev.yu_gi_ohdatabase, PID: 5020
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.customtabs.CustomTabsSession.validateRelationship(int, android.net.Uri, android.os.Bundle)' on a null object reference
        at android.support.customtabs.TrustedWebUtils.launchAsTrustedWebActivity(TrustedWebUtils.java:134)
        at android.support.customtabs.trusted.LauncherActivity$TwaCustomTabsServiceConnection.onCustomTabsServiceConnected(LauncherActivity.java:199)
        at android.support.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:44)
        at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1634)
        at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1663)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

AndroidManifest.xml: AndroidManifest.xml中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ocdev.yu_gi_ohdatabase">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ygo_fore"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ygo_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="asset_statements"
            android:resource="@string/asset_statements" />
        <activity
            android:name="android.support.customtabs.trusted.LauncherActivity">

            <!-- Edit android:value to change the url opened by the TWA -->
            <meta-data
                android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="https://db.ygoprodeck.com" />

            <!-- This intent-filter adds the TWA to the Android Launcher -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <!--
              This intent-filter allows the TWA to handle Intents to open
              airhorner.com.
            -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE"/>

                <!-- Edit android:host to handle links to the target URL-->
                <data
                    android:scheme="https"
                    android:host="db.ygoprodeck.com"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Module build.gradle: 模块build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.ocdev.yu_gi_ohdatabase"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:3a71a75c9f'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
}

Project build.gradle: 项目build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I also tested my release apk on Android Emulators via Browserstack and I receive the exact same issue. 我还通过Browserstack在Android Emulators上测试了我的发布apk,我收到了完全相同的问题。 I also received the issue on some physical devices I test such as Samsung Galaxy S7 Edge but the strange thing is that I tested a different Galaxy S7 Edge and it worked without issues. 我也在我测试的一些物理设备上收到了问题,例如三星Galaxy S7 Edge,但奇怪的是我测试了一个不同的Galaxy S7 Edge并且它没有问题。 From what I have tested so far, I'd guess it works on 50% of the devices I've tested. 从我到目前为止测试的结果来看,我猜它可以在我测试的50%的设备上运行。 I'm not an inherit Android developer so I am struggling to find the cause of this issue and why it works fine and some devices and not on others. 我不是一个继承Android开发人员,所以我很难找到这个问题的原因,为什么它工作正常和一些设备而不是其他设备。

I have the same problem. 我也有同样的问题。

I noticed that if I update chrome to the last version (currently 72) the TWA works great. 我注意到如果我将chrome更新到最后一个版本(目前为72),TWA的效果很好。 What is annoying is that there is no error message for the user to make him update chrome. 令人讨厌的是,用户没有错误消息让他更新chrome。

IMO this makes TWA currently not usable. IMO这使得TWA目前无法使用。

I posted this question on the Chromium forums and got redirected to a temporary fix listed here . 我在Chromium论坛上发布了这个问题,并被重定向到此处列出的临时修复程序。

In short, they are aware of the issue and hope to have a permanent solution out soon so the temporary fix shouldn't be needed for long. 简而言之,他们意识到了这个问题,并希望尽快找到永久性的解决方案,因此不应该长期需要临时解决方案。

The answer given: 答案是:

For the moment, you can change the last parameter to CustomTabsClient#getPackageName here to true. 目前,你可以改变的最后一个参数CustomTabsClient#getPackageName 这里为true。 This parameter is 'ignoreDefault' and as you can probably guess will make the package selection ignore the user's default. 这个参数是'ignoreDefault',你可能猜到它会使包选择忽略用户的默认值。 Ideally though this won't be necessary for long. 理想情况下,这不会很长时间。

我的TWA也有这个问题,我发现如果浏览器默认设置为chrome或edge,那么它将工作但不适用于三星浏览器和Firefox

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM