0

我们正在开发 PWA 应用程序以将其提交到 Play 商店。我们使用 TWA,遵循所有概念,但不知何故我们无法隐藏 URL BAR。

数字资产链接已配置和测试。我们已经用 TWA 连接了网站,我们已经成功测试了映射编辑器,我们已经添加了意图过滤器,成功测试了与 assetslinks.json 的关联

安卓清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="eu.clubforceone.mobile">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/appName"
        android:supportsRtl="true"
        android:theme="@style/Theme.LauncherActivity">

        <meta-data
            android:name="asset_statements"
            android:resource="@string/assetStatements" />

        <activity
            android:name="android.support.customtabs.trusted.LauncherActivity"
            android:label="@string/appName">
            <tools:validation testUrl="https://login.clubforce.eu" />

            <meta-data
                android:name="android.support.customtabs.trusted.DEFAULT_URL"
                android:value="@string/launchUrl" />

            <meta-data
                android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
                android:resource="@color/colorPrimary" />

            <meta-data
                android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
                android:resource="@drawable/splash" />

            <meta-data
                android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
                android:resource="@color/whiteColor" />

            <meta-data
                android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
                android:value="300" />

            <meta-data
                android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
                android:value="@string/providerAuthority" />

            <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="login.clubforce.eu" />
            </intent-filter>
        </activity>

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="@string/providerAuthority"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

        <service
            android:name="android.support.customtabs.trusted.TrustedWebActivityService"
            android:enabled="@bool/enableNotification"
            android:exported="@bool/enableNotification">

            <intent-filter>
                <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </service>

    </application>
</manifest>

build.gradle 模块应用

apply plugin: 'com.android.application'

def twaManifest = [
        applicationId: 'eu.clubforceone.mobile',
        hostName: 'login.clubforce.eu', // The domain being opened in the TWA.
        launchUrl: '/', // The start path for the TWA. Must be relative to the domain.
        name: 'Clubforce', // The name shown on the Android Launcher.
        themeColor: '#283795', // The color used for the status bar.
        backgroundColor: '#F6F6F6', // The color used for the splash screen background.
        whiteColor: '#FFFFFF', // The color used for the splash screen background.
        enableNotifications: false // Set to true to enable notification delegation
]

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "eu.clubforceone.mobile"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 20003
        versionName '2.2'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        // The name for the application on the Android Launcher
        resValue "string", "appName", twaManifest.name

        // The URL that will be used when launching the TWA from the Android Launcher
        resValue "string", "launchUrl", "https://" + twaManifest.hostName + twaManifest.launchUrl

        // The hostname is used when building the intent-filter, so the TWA is able to
        // handle Intents to open https://svgomg.firebaseapp.com.
        resValue "string", "hostName", twaManifest.hostName

        // This variable below expresses the relationship between the app and the site,
        // as documented in the TWA documentation at
        // https://developers.google.com/web/updates/2017/10/using-twa#set_up_digital_asset_links_in_an_android_app
        // and is injected into the AndroidManifest.xml
        resValue "string", "assetStatements",
                '[{ \\"relation\\": [\\"delegate_permission/common.handle_all_urls\\"],' +
                        '\\"target\\": {\\"namespace\\": \\"web\\", \\"site\\": \\"https://' +
                        twaManifest.hostName + '\\"}}]'

        // This attribute sets the status bar color for the TWA. It can be either set here or in
        // `res/values/colors.xml`. Setting in both places is an error and the app will not
        // compile. If not set, the status bar color defaults to #FFFFFF - white.
        resValue "color", "colorPrimary", twaManifest.themeColor

        // Sets the color for the background used for the splash screen when launching the
        // Trusted Web Activity.
        resValue "color", "backgroundColor", twaManifest.backgroundColor

        // used only for specific situation where white color is needed
        resValue "color", "whiteColor", twaManifest.whiteColor


        // Defines a provider authority fot the Splash Screen
        resValue "string", "providerAuthority", twaManifest.applicationId + '.fileprovider'

        // The enableNotification resource is used to enable or disable the
        // TrustedWebActivityService, by changing the android:enabled and android:exported
        // attributes
        resValue "bool", "enableNotification", twaManifest.enableNotifications.toString()
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.github.GoogleChrome.custom-tabs-client:customtabs:91b4a1270b511ce70245d3440e6267762c5f1c6b'
}

资产链接.json

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "eu.clubforceone.mobile",
    "sha256_cert_fingerprints":
    ["CD:D5:D1:54:AC:8F:17:0B:8A:E6:5D:0F:C2:07:1D:FC:D7:2C:16:EE:66:A4:D9:F6:DA:1C:57:12:1B:57:A5:F9"]
  }
}]

我只是不知道该怎么办...

这是我运行“keytool -list -printcert -jarfile app-release.apk”的结果

Signer #1:

Signature:

Owner: deleted for privacy reason
Issuer: deleted for privacy reason
Serial number: 6beb859e
Valid from: Sun Apr 01 14:33:45 CEST 2018 until: Thu Aug 17 14:33:45 CEST 2045
Certificate fingerprints:
     MD5:  29:FC:96:6C:FC:D0:E4:69:BC:BC:B1:95:01:DA:6D:2D
     SHA1: 00:7E:76:27:F9:5E:51:83:6A:77:70:57:90:A1:B7:56:66:66:A3:99
     SHA256: CD:D5:D1:54:AC:8F:17:0B:8A:E6:5D:0F:C2:07:1D:FC:D7:2C:16:EE:66:A4:D9:F6:DA:1C:57:12:1B:57:A5:F9
     Signature algorithm name: SHA256withRSA
     Version: 3

Extensions: 

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 06 A2 63 AE E8 BD 9A 56   00 66 4E 8B 9C 09 EA 13  ..c....V.fN.....
0010: 20 C8 E5 4E                                         ..N
]
]
4

3 回答 3

0

如果您让 Play 商店管理您的签名,请检查您的assetlinks.json 是否包含来自您的 Play 商店设置的 SHA215,而不是由 keytool 生成的。如this other answer中所述。

也就是说,我和你的情况一样。我也无法从我的 TWA 应用程序中删除 URL 栏。

于 2019-08-17T18:05:01.193 回答
0

'assetlinks.json' 文件中的 'package_name' 字段需要指向应用程序包名(与 applicationId 相同)。

以下是assetlinks.json 文件的样子:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "eu.clubforceone.mobile",
    "sha256_cert_fingerprints":
    ["CD:D5:D1:54:AC:8F:17:0B:8A:E6:5D:0F:C2:07:1D:FC:D7:2C:16:EE:66:A4:D9:F6:DA:1C:57:12:1B:57:A5:F9"]
  }
}]
于 2019-08-17T09:08:39.083 回答
0

您可以使用 PWA2APK 来简化程序: PWA2APK

于 2019-08-16T14:20:42.003 回答