4

我正在尝试使用此处的 Google TWA 指南让我的 PWA 应用程序正常工作:

https://developers.google.com/web/updates/2019/02/using-twa

我已经从头到尾多次完全遵循该指南,但似乎无法让它在任何时候隐藏 URL 栏。

我已将 apk(release) 上传到 Google Play 控制台,并允许它为我进行签名。

我基本上已经完成了关于 SO 的所有问题,但似乎没有一个解决方案对我有用,或者我已经正确设置了它们。

我已经尝试并检查过的注意事项:

  • 我已将 SHA256 指纹复制到 Play 管理中心提供给我的 assetslinks.json 文件中。没用。
  • 我在我的assetlinks.json 中使用了我在Android Studio 中设置的手动生成的SHA256 指纹。没用。
  • 在上述两种情况下,我都尝试将生成的 apk 手动加载到我的手机上,而不是从 Play 管理中心加载 apk。没用。
  • 我尝试使用 Android Studio 在我的手机上使用带有 USB 调试的开发者模式安装应用程序(尝试了发布和调试两种方式)。也没有工作。
  • 尝试将 strings.xml 中的命名空间更改为“android_app”以匹配assetlinks.json 文件中的命名空间,这有点远。没用。
  • 确认assetlinks.json 文件使用资产链接生成器工作:https ://developers.google.com/digital-asset-links/tools/generator
  • 我的assetlinks.json 路径是/.well-known/assetlinks.json
  • 我的意图似乎有效(单击 Google 搜索结果中的链接将提示启动应用程序,并且关联保持不变)

我的 build.gradle(模块)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.mypwadomain.www"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 3
        versionName "0.1.9"
        testInstrumentationRunner "androidx.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 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:d08e93fce3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

我的 AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mypwadomain.www">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="PWAAppName"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
        <meta-data
            android:name="asset_statements"
            android:resource="@string/asset_statements" />
        <activity
            android:name="android.support.customtabs.trusted.LauncherActivity">

            <meta-data
                android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="https://www.mypwadomain.com/login" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE"/>

                <data
                    android:scheme="https"
                    android:host="www.mypwadomain.com"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

我的strings.xml

<resources>
    <string name="app_name">PWAAppName</string>
    <string name="asset_statements">
        [{
            \"relation\": [\"delegate_permission/common.handle_all_urls\"],
            \"target\": {
                \"namespace\": \"web\",
                \"site\": \"https://www.mypwadomain.com\"}
        }]
    </string>
</resources>

我的assetlinks.json

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "web",
    "site": "https://www.mypwadomain.com"
  }
},{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "com.mypwadomain.www",
    "sha256_cert_fingerprints": ["...Google Signed Fingerprint..."] }
}]

该应用程序本身的 Lighthouse 审计功能恢复了 100 PWA 兼容性,并且添加到主屏幕在 Android 和 iOS 设备上都运行良好。

我对此很陌生。我主要是一名 PHP 开发人员,实际的应用程序运行良好。几天前我第一次安装了Android Studio。从好的方面来说,我使用 PHPStorm,它也是由 JetBrains 制造的,所以这部分有助于学习曲线。

任何关于我可以检查的其他内容的帮助或建议将不胜感激。

编辑:我通过 android studio 加载了 logcat(我在 Windows 上工作)。然后我在调试模式下运行应用程序,结果日志如下。没有 OriginVerifier 或 digital_asset_links 的实例

2019-06-20 11:18:12.440 12042-12042/? E/Zygote: accessInfo : 1
2019-06-20 11:18:12.444 12042-12042/? I/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c94,c257,c512,c768, pkgname=com.mypwaapp.www 
2019-06-20 11:18:12.453 12042-12042/? I/m.mypwaapp.ww: Late-enabling -Xcheck:jni
2019-06-20 11:18:12.609 12042-12042/com.mypwaapp.www W/ActivityThread: Application com.mypwaapp.www is waiting for the debugger on port 8100...
2019-06-20 11:18:12.610 12042-12042/com.mypwaapp.www I/System.out: Sending WAIT chunk
2019-06-20 11:18:13.814 12042-12042/com.mypwaapp.www I/System.out: Debugger has connected
2019-06-20 11:18:13.815 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.017 12042-12042/com.mypwaapp.www I/chatty: uid=10350(com.mypwaapp.www) identical 1 line
2019-06-20 11:18:14.220 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.423 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.625 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:14.828 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:15.032 12042-12042/com.mypwaapp.www I/chatty: uid=10350(com.mypwaapp.www) identical 1 line
2019-06-20 11:18:15.235 12042-12042/com.mypwaapp.www I/System.out: waiting for debugger to settle...
2019-06-20 11:18:15.440 12042-12042/com.mypwaapp.www I/System.out: debugger has settled (1500)
2019-06-20 11:18:15.457 12042-12042/com.mypwaapp.www D/ConnectivityManager_URSP: Ursp sIsUrsp=false, sIsCheckUrsp=false, uid=10350
2019-06-20 11:18:15.478 12042-12042/com.mypwaapp.www D/Proxy: urspP is null: 10350
2019-06-20 11:18:15.788 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: JIT profile information will not be recorded: profile file does not exits.
2019-06-20 11:18:15.831 12042-12042/com.mypwaapp.www I/chatty: uid=10350(com.mypwaapp.www) identical 10 lines
2019-06-20 11:18:15.835 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: JIT profile information will not be recorded: profile file does not exits.
2019-06-20 11:18:15.948 12042-12042/com.mypwaapp.www I/InstantRun: starting instant run server: is main process
2019-06-20 11:18:16.101 12042-12063/com.mypwaapp.www D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
2019-06-20 11:18:16.403 12042-12042/com.mypwaapp.www D/TWAProviderPicker: Found Custom Tabs provider: com.sec.android.app.sbrowser
2019-06-20 11:18:16.404 12042-12042/com.mypwaapp.www D/TWAProviderPicker: Found no TWA providers, using first Custom Tabs provider: com.sec.android.app.sbrowser
2019-06-20 11:18:16.410 12042-12042/com.mypwaapp.www D/TWALauncherActivity: Using URL from Manifest (https://www.mypwaapp.com/login).
2019-06-20 11:18:17.330 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-06-20 11:18:17.335 12042-12042/com.mypwaapp.www W/m.mypwaapp.ww: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-06-20 11:18:17.506 12042-12042/com.mypwaapp.www D/OpenGLRenderer: Skia GL Pipeline
2019-06-20 11:18:17.528 12042-12042/com.mypwaapp.www D/EmergencyMode: [EmergencyManager] android createPackageContext successful
2019-06-20 11:18:17.678 12042-12042/com.mypwaapp.www D/InputTransport: Input channel constructed: fd=81
2019-06-20 11:18:17.686 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: setView = DecorView@fe5f2d3[LauncherActivity] TM=true MM=false
2019-06-20 11:18:17.717 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: Surface release. android.view.WindowManagerGlobal.setStoppedState:669 android.app.Activity.performStop:7646 android.app.ActivityThread.callActivityOnStop:4352 android.app.ActivityThread.performStopActivityInner:4330 android.app.ActivityThread.handleStopActivity:4405 android.app.servertransaction.StopActivityItem.execute:41 android.app.servertransaction.TransactionExecutor.executeLifecycleState:145 android.app.servertransaction.TransactionExecutor.execute:70 
2019-06-20 11:18:17.779 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: dispatchAttachedToWindow
2019-06-20 11:18:17.839 12042-12042/com.mypwaapp.www D/ViewRootImpl@c9324c2[LauncherActivity]: Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x1 surface={valid=false 0} changed=false

编辑 2:我确实在 logcat 提要中找到了这个:

2019-06-20 12:23:56.772 6226-11769/? I/SingleHostAsyncVerifier: Verification result: checking for a statement with source a: # bpti@709f0232
    w: 29
    , relation delegate_permission/common.handle_all_urls, and target b <
      a: "com.mypwaapp.www"
      b: # bptg@e7d522a2
      w: 118
    >
    w: 120
     --> false.

不确定是否相关。

4

2 回答 2

1

当我在解决问题时清除手机(Samsung Note 9)上的设置时,我的默认浏览器必须已重置为三星浏览器。我将默认浏览器设置为 Chrome。它工作正常。

感谢安德烈班​​ :)

于 2019-06-27T00:16:20.450 回答
-1

我有一个与@Incredibad 类似的案例,我同时安装了 Chrome 和 Chrome Dev,Chrome dev 成为默认浏览器。

于 2020-02-20T15:59:13.340 回答