受信任的Web活动-地址栏不隐藏(Chrome for Android 72)

c9qzyr3d  于 2023-01-19  发布在  Android
关注(0)|答案(8)|浏览(178)

我已经按照this指南学习了如何使用可信网络活动。一切正常,但地址栏仍然出现。一开始我认为这是因为当应用程序寻找 * assetlinks. json * 时,响应是404。修复了它,但没有删除地址栏。我错过了什么吗?

    • Chrome浏览器版本:**72.0.3626.96
    • 安卓系统版本:**7.1.2(LineageOS 14.1)
    • 资产链接网站**
[{
  "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"] }
}]
    • 安卓清单. 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>
    • 资源/值/字符串. 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>
    • 构建. 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
    • 屏幕截图**
yptwkmov

yptwkmov1#

您可能已选择让Google Play使用他们生成的密钥对您的版本进行签名,并且仅使用您的密钥进行上传。
如果您已注册,请转至Google Play控制台版本管理-〉应用签名,复制应用签名证书SHA-256指纹并将其放入assetlinks.json文件。

de90aj5v

de90aj5v2#

我今天也遇到了同样的问题,这是我学到的:
在尝试测试你的安卓应用程序之前,请在这里测试你的陈述:
https://developers.google.com/digital-asset-links/tools/generator
填写域、包和指纹,然后单击"测试声明"
如果你看到

  • *"成功!托管[您的Web应用]授予应用到[android软件包]的深度链接。"**,则表示您的Web应用配置正确,但您的设备或应用存在问题。

你很可能会看到

  • "无效输入字段"*

你可以打开Chrome浏览器控制台的网络选项卡来查看服务器输出,可能你会看到类似"无效站点(URL不能包含路径组件、登录信息、查询参数或片段标识符)"的内容
要解决此问题,您应该将assetlinks.json文件放在Web应用的***根目录下***,
https://slexom.gitlab.io/.well-known/assetlinks.json。您可以 checkout 我的示例repository。正如您所看到的,我的文件可以从https://antipovandrey.github.io/PWA/.well-known/assetlinks.json访问

ngynwnxp

ngynwnxp3#

当使用谷歌SHA-256或只是改变指纹代码一定要清除 chrome 缓存有关您以前的应用程序或检查缓存控制.json

wd2eg0qa

wd2eg0qa4#

在我的例子中,我运行的应用程序的风格是错误的,然后我用什么签名。只有我的应用程序的发布版本是使用SHA密钥登录的,我运行的应用程序在调试版本。
当我纠正味道的时候,它和预期的一样运行。

y4ekin9u

y4ekin9u5#

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

7fyelxc5

7fyelxc56#

经过一个星期的挣扎,终于成功了,这里是我的两分钱:
如果您选择让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对象本身,否则验证将失败)
请注意,新构建的软件包是使用Upload Key签名的,而不是使用App Signing Key签名的,因此如果您尝试直接测试本地构建的.apk,assetlink验证将失败,URL栏将可见。
要真正测试链接是否有效,你必须从商店下载应用程序(生产/内部测试/开放测试等),因为应用程序是由谷歌签署的App Signing certificate sha_256发布后,已成功推出到商店。

5us2dqdw

5us2dqdw7#

仅供参考:我在几个小时前就遇到了这个问题,我发现了这个问题,问题是我在通过bubblewrap init命令生成android项目时使用的实际包名生成assetlinks.json文件时使用了不同的包名。
很高兴看到网址栏现在被隐藏起来了,真是太神奇了!

e4yzc0pl

e4yzc0pl8#

同样的情况,assetlinks.json验证成功,但URL栏存在,建议Google Play控制台的SHA-256不工作

相关问题