滅入るんるん

何か書きます

Android Instant AppsをGoogle Playに公開するときはdefault-urlに対応するintent filterにStringリソースを使ってるとデフォルトURLとの関連付けができてないと怒られる

このアプリの作成中に躓いたポイントです。

github.com

Instant Appsを作るにはApp Linksに対応する必要があります。

Android Studioに付いてる標準のApp Link Assistantを使うと楽にintent filterを用意できるわけですが、http/https両方を追加するとこのようになります。

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data
                    android:scheme="http"
                    android:host="foodsearch.meilcli.net"
                    android:path="/app/splash"/>
            </intent-filter>
            <intent-filter>
                <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="foodsearch.meilcli.net"
                    android:path="/app/splash"/>
            </intent-filter>

            <meta-data
                android:name="default-url"
                android:value="https://foodsearch.meilcli.net/app/splash"/>

ぶっちゃけスマートじゃないですよね?文字列をべた書きしてたりするし、intent filterタグは2つあるし

            <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="http"/>
                <data android:scheme="https"/>
                <data android:host="@string/applicationServerHost"/>
                <data android:path="@string/linkUrlPathOfMainView"/>
            </intent-filter>

他の画面ではこのように定義したので、default-urlを定義しているActivityのintent filterも同じようにしようとすると罠にハマります

どういうことかというと、Google Play Consoleのインスタントアプリのところに作成したApp Bundleをアップロードすると、App Bundleの中身を自動チェックしてくれるわけですが、そのバリエーション機能の実装がお粗末感のあるようなものっぽいです。 バリデーション機能によってdefault-urlが設定されていて、そのURLが認証が正しいかをチェックしてくれたりとバリデーション機能は便利ですが、default-urlのURLをintent filterで関連付けられているかのチェックもしているようです。そこで、intent filterにstringリソースを設定しているとバリデーション機能がリソースの値まで追ってくれず、default-urlとの関連付けができてないとのことで怒られます。そして公開もできません。

そのうち機能改善で直ると思いますが、とうぶんはdefault-urlと関連付けているintent filterにはべた書きしたほうがよさそうです。

という感じに発覚後のツイート↓


追記

manifestにString Resourceを使ってるのが悪いなら直接埋め込めばいいのではということことで、manifestPlaceholdersを使用すればよかった。

android {
    defaultConfig {
        manifestPlaceholders  = [
            applicationServerHost: applicationServerHost, // url : ""みたいに設定する、右辺は他で定義した変数
            defaultUrlPath: linkUrlPathOfSplashView
        ]
    }
}
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="http"/>
                <data android:scheme="https"/>
                <data android:host="${applicationServerHost}"/>
                <data android:path="${defaultUrlPath}"/>
            </intent-filter>

            <meta-data
                android:name="default-url"
                android:value="https://${applicationServerHost}${defaultUrlPath}"/>

これで無事Google Play Consoleを通過したし、リソースの一元管理もできてWin-Winですね