19

我已按照指南学习如何使用受信任的 Web 活动。一切都很好,但地址栏仍然出现。一开始我认为这是因为当应用程序正在寻找assetlinks.json时,响应是404。修复了它,但删除地址栏没有运气。我错过了什么吗?

铬版本: 72.0.3626.96

安卓版本: 7.1.2(LineageOS 14.1)

资产链接.json

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "com.example.twa_test",
    "sha256_cert_fingerprints": ["2A:32:7D:B7:4D:0B:A5:6A:72:47:86:A3:2F:A6:BB:D8:26:DE:AB:7E:8B:EA:C7:16:80:EA:C3:F1:50:E7:8E:D1"] }
}]

AndroidManifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_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://slexom.gitlab.io/namya/" />

            <!-- 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="slexom.gitlab.io/namya/" />
            </intent-filter>
        </activity>
    </application>
</manifest>

res/values/strings.xml

<resources>
    <string name="app_name">Namya</string>
    <string name="asset_statements">
        [{
            \"relation\": [\"delegate_permission/common.handle_all_urls\"],
            \"target\": {
                \"namespace\": \"web\",
                \"site\": \"https://slexom.gitlab.io/namya/\"}
        }]
    </string>
</resources>

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
}

build.gradle(模块:应用程序)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.twa_test"
        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'
}

日志猫

2019-02-08 18:19:01.918 10880-10880/? I/art: Late-enabling -Xcheck:jni
2019-02-08 18:19:02.352 10880-10880/com.example.twa_test W/System: 
ClassLoader referenced unknown path: /data/app/com.example.twa_test-1/lib/arm
2019-02-08 18:19:02.403 10880-10880/com.example.twa_test I/InstantRun: 
starting instant run server: is main process
2019-02-08 18:19:02.478 10880-10896/com.example.twa_test D/libEGL: loaded /system/lib/egl/libEGL_mali.so
2019-02-08 18:19:02.510 10880-10896/com.example.twa_test D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
2019-02-08 18:19:02.660 10880-10880/com.example.twa_test W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
2019-02-08 18:19:02.727 10880-10896/com.example.twa_test D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:787)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:727)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:858)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:821)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:518)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:426)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:377)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.support.v7.app.AppCompatDelegateImpl.onPostCreate(android.os.Bundle) (AppCompatDelegateImpl.java:299)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.support.v7.app.AppCompatActivity.onPostCreate(android.os.Bundle) (AppCompatActivity.java:98)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.app.Instrumentation.callActivityOnPostCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1200)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2666)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2751)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1496)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.os.Looper.loop() (Looper.java:154)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6186)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-02-08 18:19:02.920 10880-10880/com.example.twa_test I/art:     at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:889)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:779)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.twa_test-1/base.apk", zip file "/data/app/com.example.twa_test-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.twa_test-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.tw
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:787)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:727)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:858)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:821)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:518)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:426)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:377)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.support.v7.app.AppCompatDelegateImpl.onPostCreate(android.os.Bundle) (AppCompatDelegateImpl.java:299)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.support.v7.app.AppCompatActivity.onPostCreate(android.os.Bundle) (AppCompatActivity.java:98)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.app.Instrumentation.callActivityOnPostCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1200)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2666)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2751)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1496)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.os.Looper.loop() (Looper.java:154)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6186)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:889)
2019-02-08 18:19:02.921 10880-10880/com.example.twa_test I/art:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:779)
2019-02-08 18:19:03.284 10880-10880/com.example.twa_test D/LauncherActivity: Using URL from Manifest (https://slexom.gitlab.io/namya/).
2019-02-08 18:19:03.284 10880-10880/com.example.twa_test D/LauncherActivity: Launching Trusted Web Activity.
2019-02-08 18:19:03.470 10880-10923/com.example.twa_test I/Mali: Mali API Version : 401
2019-02-08 18:19:03.470 10880-10923/com.example.twa_test I/Mali: Mali REVISION: Linux-r4p0-00rel0  BUILD_DATE: 2014-11-10 20:23:11 
2019-02-08 18:19:03.477 10880-10923/com.example.twa_test I/OpenGLRenderer: Initialized EGL, version 1.4
2019-02-08 18:19:03.477 10880-10923/com.example.twa_test D/OpenGLRenderer: Swap behavior 1
2019-02-08 18:19:03.598 10880-10880/com.example.twa_test W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView

截屏 截屏

4

7 回答 7

37

您可能已选择让 Google Play 使用他们生成的密钥为您的版本签名,并且仅使用您的密钥进行上传。

如果您这样做了,请转到 Google Play Console Release Management -> App Signing并复制应用签名证书SHA-256 指纹并将其放入assetlinks.json文件中。

于 2019-02-17T23:39:09.347 回答
11

我今天遇到了同样的问题,这就是我所学到的:
在尝试测试您的 android 应用程序之前,请在此处测试您的声明:
https
://developers.google.com/digital-asset-links/tools/generator 填写域、包和指纹,然后单击“测试声明”
如果您看到
“成功!主机 [您的网络应用程序] 授予应用程序深度链接到 [android 包]。” ,那么您的网络应用程序配置正确,并且您的设备或应用程序有问题。
您很可能会看到
“无效的输入字段”
您可以在“网络”选项卡上打开 Chrome 控制台以查看服务器输出。可能您会看到类似“无效站点(URL 不能包含路径组件、登录信息、查询参数或片段标识符)”之
类的内容。要解决此问题,您应该将assetlinks.json 文件放在 Web 应用程序的根目录下
https://slexom.gitlab.io/.well-known/assetlinks.json 在你的情况下。您可以签出我的示例存储库。如您所见,可以从https://antipovandrey.github.io/PWA/.well-known/assetlinks.json访问我的文件

于 2019-02-09T16:56:46.730 回答
4

使用 google SHA-256 或仅更改指纹代码时,请务必清除有关您以前的应用程序的 chrome 缓存或检查 .json 的缓存控制

于 2020-01-29T08:11:31.047 回答
2

就我而言,我以错误的方式运行应用程序,然后是我用于签名的方式。只有我的应用程序的发布版本使用 SHA 密钥登录,并且我在调试版本中运行该应用程序。

当我纠正味道时,它按预期运行。

于 2019-06-12T13:57:07.100 回答
1

对于那些仍然面临这个问题的人,很可能在assetlinks.json 中,您使用的是来自“上传证书”而不是来自“应用程序签名证书”的 SHA256。您可以在 Google Play 控制台 -> 发布管理 -> 应用签名中找到这两个证书。

于 2019-12-27T18:49:23.280 回答
0

经过一周的努力并最终在这里成功是我的两分钱:

如果您选择让 Google 为您管理密钥,则有两个密钥, App Signing KeyUpload key.

遵循通用步骤(设置->应用程序完整性->创建Digital Asset Links JSON

  [
    {
      "relation": ["delegate_permission/common.handle_all_urls"],
      "target": {
        "namespace": "android_app",
        "package_name": "PACKAGE.NAME.HERE",
        "sha256_cert_fingerprints":["APP:SIGNING:CERTIFICATE:SHA_256:FINGERPRINT"]
       }
    }
  ]

并将其暴露在:

https://your.domain/.well-known/assetlinks.json

(访问 url 以验证 json 必须是列表/数组,而不仅仅是 JSON 对象本身,否则验证将失败)

请注意,如果您尝试直接测试本地构建的 .apk 并且 URL 栏将可见,那么资产链接验证将失败,请注意,新构建的包是用Upload Key和 NOT签名的。App Signing Key

要真正测试链接是否有效,您必须从商店下载应用程序(生产/内部测试/开放测试等),因为该应用程序是App Signing certificate sha_256在发布成功推出商店后由谷歌签署的。

于 2021-12-15T12:24:07.953 回答
-2

同样的故事,assetlinks.json 验证成功,但 url 栏存在,建议来自 google play 控制台的 SHA-256 不起作用

于 2020-01-24T07:54:50.177 回答