Androidアプリリンク実装編:assetlinks.jsonの作成・配置とManifest設定
前回の記事では、iOS向けにユニバーサルリンクを実装しました。
今回は同じHTTPS環境を使い、
Androidアプリが特定のURLを検知して自動起動する「Android App Links」 を実装します。
Android App Linksも、iOSと同様に
- サーバ側設定(assetlinks.json)
- アプリ側設定(intent-filter + autoVerify)
の両方が一致している必要があります。
1. assetlinks.json の作成
Androidでは、apple-app-site-association の代わりに
assetlinks.json を使用します。
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.yourname.testapp",
"sha256_cert_fingerprints": [
"AA:BB:CC:DD:EE:FF:..."
]
}
}
]
各項目の説明
- package_name
- AndroidアプリのPackage名
- sha256_cert_fingerprints
- アプリ署名のSHA256フィンガープリント
SHA256の取得方法
開発用(debug)の場合:
keytool -list -v \
-keystore ~/.android/debug.keystore \
-alias androiddebugkey \
-storepass android \
-keypass android
SHA256: の値をコピーします。
デプロイ版証明情報
Play Store配布版では「Google Play App Signing」によりアプリが再署名されます。
そのため、ローカルのrelease署名のSHA-256ではなく、Google Play Consoleの「アプリの完全性」に表示される「Play アプリ署名」から確認できるSHA-256フィンガープリントを設定する必要があります。

2. サーバーへの配置(Nginx)
作成したファイルをサーバのドキュメントルートの .well-known ディレクトリに配置します。
https://example.ddns.net/.well-known/assetlinks.json
Docker環境での配置例
./docker-compose/nginx/.well-known/assetlinks.json
Nginx設定
assetlinks.json ファイルは前回記事のAASAファイルと同様にブラウザからアクセスした際に application/json として返される必要があります。
nginx.conf の server (listen 443) 内に以下を追加します。
location /.well-known/assetlinks.json {
default_type application/json;
}
動作確認
curl -I https://example.ddns.net/.well-known/assetlinks.json
レスポンスヘッダが
Content-Type: application/json
になっていればOKです。
3. AndroidManifest.xml の設定
次にアプリ側の設定です。
AndroidManifest.xml の対象Activityに
intent-filter を追加します。
<activity
android:name=".MainActivity"
android:exported="true">
<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="example.ddns.net"
android:pathPrefix="/articles" />
</intent-filter>
</activity>
重要ポイント
android:autoVerify="true"
→ ドメイン所有確認を自動実行
android:pathPrefix
→ /articles/* を対象にする
4. アプリ内でのURL受信処理(Kotlin)
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.data?.let { uri ->
Log.d("AppLink", "Deep link: $uri")
}
}
5. 動作テスト
以下の手順でテストを行います。
- 実機にアプリをインストール
- Chromeやメモ帳にURLを貼る
https://example.ddns.net/articles/123
- タップする
- アプリが直接起動すれば成功
ADBコマンドを使ったテスト
実機でのタップに加えて、ターミナルからADBコマンドで直接テストすることも可能です。
adb shell am start -W -a android.intent.action.VIEW -d "https://example.ddns.net/articles/123" com.yourname.testapp
iOSとの比較
| 項目 | iOS | Android |
|---|---|---|
| サーバファイル | apple-app-site-association | assetlinks.json |
| 配置場所 | .well-known | .well-known |
| アプリ側設定 | Associated Domains | intent-filter |
| 証明確認 | TeamID+BundleID | SHA256証明書 |
まとめ
今回の設定で:
- iOS → ユニバーサルリンク
- Android → アプリリンク
両方に対応した完全なマルチプラットフォームリンク環境が完成しました。
ホームサーバでHTTPSを構築している方であれば、
この構成はそのまま再利用可能です。
Discussion