effidevFlutter・Cloudflareエッジ・クラウドコスト最適化
日本語

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

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.jsonContent-Type: application/jsonで正しく応答し、SHA-256フィンガープリントを含んでいる必要があります。
  • iOS Universal Links: /.well-known/apple-app-site-association (AASA)に正しいappID (<TEAM_ID>.<BUNDLE_ID>)を設定します。
  • Flutterハンドリング: app_linksGoRouterを組み合わせ、コールドスタート時とバックグラウンド実行時の両方でパラメーターを安全に取得します。
  • CI自動化: GitHub Actionsでサーバー上の設定ファイルを事前に自動検証し、ディープリンクの破損を防止します。

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によるテスト


結論

CI環境でApp Linksのドメイン検証を自動化することで、本番環境でのディープリンク不具合を確実に防ぐことができます。