このアプリの作成中に躓いたポイントです。
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にはべた書きしたほうがよさそうです。
という感じに発覚後のツイート↓
おいぐーぐるううううううううううううううううううう
— 🐧#⃣ (@penguin_sharp) 2018年12月18日
Google Play Consoleのバリデーション機能ぐらいちゃんと実装しろ
— 🐧#⃣ (@penguin_sharp) 2018年12月18日
Android Instant Appを作る際はdefault-urlに対応しているIntent FilterにはURLやPathをべた書きするようにしましょう
— 🐧#⃣ (@penguin_sharp) 2018年12月18日
丁寧にString Resourceで宣言してたりするとGoogle Play Consoleのバリデーション機能が値まで追いかけてくれなくてInstant AppとデフォルトURLが関連づいてないと怒られます
追記
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ですね