Flutter App Links / Universal Linksの自動検証とCIディープリンクテスト自動化ガイド

モバイルアプリ開発において、ディープリンク(Deep Linking)はユーザー誘導や決済リダイレクトの要です。従来のカスタムURLスキーム(myapp://)はハイジャックのリスクがあるため、GoogleおよびAppleはドメイン検証を伴うAndroid App LinksおよびiOS Universal Linksの採用を強く推奨しています。
本記事では、Domain Associationファイルの設定方法、Flutter側(GoRouter + app_links)の受信処理、およびGitHub Actionsによる自動検証パイプラインの構築手順を解説します。
要約
- Android App Links:
/.well-known/assetlinks.jsonがContent-Type: application/jsonで正しく応答し、SHA-256フィンガープリントを含んでいる必要があります。- iOS Universal Links:
/.well-known/apple-app-site-association(AASA)に正しいappID(<TEAM_ID>.<BUNDLE_ID>)を設定します。- Flutterハンドリング:
app_linksとGoRouterを組み合わせ、コールドスタート時とバックグラウンド実行時の両方でパラメーターを安全に取得します。- CI自動化: GitHub Actionsでサーバー上の設定ファイルを事前に自動検証し、ディープリンクの破損を防止します。
1. Flutterにおけるルーティング実装 (GoRouter + app_links)
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:app_links/app_links.dart';
final _appLinks = AppLinks();
final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/product/:id',
builder: (context, state) => ProductDetailScreen(productId: state.pathParameters['id'] ?? ''),
),
],
);
2. CLIによるテスト
-
Android CLI:
adb shell am start -a android.intent.action.VIEW \ -c android.intent.category.BROWSABLE \ -d "https://effidev.dev/product/456" -
iOS Simulator CLI:
xcrun simctl openurl booted "https://effidev.dev/product/456"
結論
CI環境でApp Linksのドメイン検証を自動化することで、本番環境でのディープリンク不具合を確実に防ぐことができます。