Flutter Android 앱도 네이티브 앱과 같은 방식으로 App Links를 받아요. AndroidManifest.xml의 Intent 필터, assetlinks.json을 통한 Digital Asset Links 검증, Activity 생명주기 메서드를 그대로 써요. Flutter는 여기에 한 단계를 더해요: FlutterActivity 가 Intent를 받고, 라우팅은 Dart 코드에서 처리해요. 이 글에서는 Android 쪽 설정을 다뤄요.
iOS와 Android를 모두 다루는 Flutter App Links 전체 가이드는 다음 글을 참고하세요: Flutter의 App Links: Android 설정 가이드. Android Manifest 설정은 다음 글을 참고하세요: 딥 링크를 위한 Android Manifest 설정.
사전 준비
- Flutter 3.19 이상(최신 stable 권장)
- 직접 관리하는 HTTPS 도메인
- assetlinks.json 호스팅 위치
https://yourdomain.com/.well-known/assetlinks.json - 앱 서명 키의 SHA-256 지문
1단계: AndroidManifest 설정
다음 파일을 수정하세요: android/app/src/main/AndroidManifest.xml. 다음 <activity> 요소 중 아래 속성이 있는 요소에 Intent 필터를 추가하세요: android:name=".MainActivity":
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme">
<!-- Default Flutter intent filters -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- App Links -->
<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="yourdomain.com"
android:pathPrefix="/products" />
<data android:scheme="https"
android:host="yourdomain.com"
android:pathPrefix="/offers" />
<data android:scheme="https"
android:host="yourdomain.com"
android:pathPrefix="/referral" />
</intent-filter>
</activity>
주요 속성:
android:autoVerify="true": Android가 Digital Asset Links로 도메인 소유권을 확인하게 해요. 이 속성이 없으면 Android가 앱을 바로 열지 않고 앱 선택 대화상자를 띄워요.android:launchMode="singleTop": 앱이 이미 실행 중이면 새 Activity를 만들지 않아요. 대신 기존 Activity가 새 Intent를 받는데, 이때 호출되는 메서드는onNewIntent.android:exported="true": Activity가 외부 앱에서 보낸 Intent를 받으려면 필요해요.
2단계: Digital Asset Links (assetlinks.json)
다음 위치에 호스팅하세요: https://yourdomain.com/.well-known/assetlinks.json:
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.yourcompany.yourapp",
"sha256_cert_fingerprints": [
"YOUR_DEBUG_KEY_FINGERPRINT",
"YOUR_RELEASE_KEY_FINGERPRINT"
]
}
}
]
인증서 지문 확인하기
디버그 키 (로컬 개발용):
keytool -list -v -keystore ~/.android/debug.keystore \
-alias androiddebugkey -storepass android 2>/dev/null | grep SHA256
릴리스 키 (Play App Signing을 쓰는 경우):
Google Play Console의 Setup > App signing > App signing key certificate > SHA-256 fingerprint에서 확인할 수 있어요.
릴리스 키 (로컬에서 서명하는 경우):
keytool -list -v -keystore /path/to/your-release-key.jks \
-alias your-key-alias
개발 중에는 디버그 지문과 릴리스 지문을 둘 다 넣으세요. 프로덕션에서는 디버그 지문을 빼도 돼요.
파일 검증
Google 검증 도구로 확인해 보세요:
# Check if your assetlinks.json is valid
curl -s "https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://yourdomain.com&relation=delegate_permission/common.handle_all_urls" | python3 -m json.tool
3단계: Dart 쪽 처리
Flutter에서 app_links 패키지 사용하기
intent URL의 app_links 패키지를 쓰는 게 Flutter에서 App Links를 처리하는 권장 방법이에요:
# pubspec.yaml
dependencies:
app_links: ^6.3.0
import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final AppLinks _appLinks;
@override
void initState() {
super.initState();
_appLinks = AppLinks();
_initDeepLinks();
}
Future<void> _initDeepLinks() async {
// Cold start: check if the app was launched from a deep link
final initialUri = await _appLinks.getInitialLink();
if (initialUri != null) {
_handleDeepLink(initialUri);
}
// Warm start: listen for new deep links
_appLinks.uriLinkStream.listen((uri) {
_handleDeepLink(uri);
});
}
void _handleDeepLink(Uri uri) {
final path = uri.path;
final productMatch = RegExp(r'^/products/([^/]+)$').firstMatch(path);
if (productMatch != null) {
final productId = productMatch.group(1)!;
Navigator.of(context).pushNamed(
'/products/detail',
arguments: {'productId': productId},
);
return;
}
final offerMatch = RegExp(r'^/offers/([^/]+)$').firstMatch(path);
if (offerMatch != null) {
final offerId = offerMatch.group(1)!;
Navigator.of(context).pushNamed(
'/offers/detail',
arguments: {'offerId': offerId},
);
return;
}
final referralMatch = RegExp(r'^/referral/([^/]+)$').firstMatch(path);
if (referralMatch != null) {
final referrerId = referralMatch.group(1)!;
_handleReferral(referrerId);
return;
}
}
void _handleReferral(String referrerId) {
// Store the referral for attribution
// Navigate to welcome screen
Navigator.of(context).pushNamed(
'/referral',
arguments: {'referrerId': referrerId},
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(/* ... */);
}
}
GoRouter 사용
GoRouter 는 딥 링킹을 기본으로 지원해요:
import 'package:go_router/go_router.dart';
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomePage(),
),
GoRoute(
path: '/products/:productId',
builder: (context, state) {
final productId = state.pathParameters['productId']!;
final ref = state.uri.queryParameters['ref'];
return ProductDetailPage(
productId: productId,
referralSource: ref,
);
},
),
GoRoute(
path: '/offers/:offerId',
builder: (context, state) {
final offerId = state.pathParameters['offerId']!;
return OfferDetailPage(offerId: offerId);
},
),
GoRoute(
path: '/referral/:referrerId',
builder: (context, state) {
final referrerId = state.pathParameters['referrerId']!;
return ReferralPage(referrerId: referrerId);
},
),
],
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
);
}
}
GoRouter는 다음과 함께 쓰면 콜드 스타트와 웜 스타트 딥 링크를 모두 자동으로 처리해요: MaterialApp.router.
4단계: App Links 동작 확인
에뮬레이터에서
# 제품 딥 링크 테스트
adb shell am start -a android.intent.action.VIEW \
-d "https://yourdomain.com/products/abc123" \
-c android.intent.category.BROWSABLE
# 오퍼 딥 링크 테스트
adb shell am start -a android.intent.action.VIEW \
-d "https://yourdomain.com/offers/deal456" \
-c android.intent.category.BROWSABLE
앱이 바로 열리면 App Links 인증에 성공한 거예요. 앱 선택 대화상자("다음으로 열기…")가 뜨면 인증에 실패한 거예요.
검증 상태 확인
# 앱의 인증된 도메인 전체 보기
adb shell pm get-app-links com.yourcompany.yourapp
출력에서 인증 상태를 확인할 수 있어요:
com.yourcompany.yourapp:
ID: abc12345
Signatures: [...]
Domains:
yourdomain.com: verified
도메인 상태가 none 또는 legacy_failure로 표시되면 assetlinks.json이 잘못됐거나 접근할 수 없는 거예요.
강제로 다시 검증
# 기존 인증 상태 초기화
adb shell pm set-app-links --package com.yourcompany.yourapp 0 all
# 재인증 실행
adb shell pm verify-app-links --re-verify com.yourcompany.yourapp
자주 겪는 문제
| 문제 | 원인 | 해결 |
|---|---|---|
| 바로 열리지 않고 앱 선택 대화상자 표시 | autoVerify failed |
assetlinks.json 확인, 지문 일치 여부 확인 |
| 앱은 열리지만 빈 화면 | 라우트 매칭 실패 | 딥 링크 핸들러에 로그 추가, 경로 매칭 확인 |
| 콜드 스타트 딥 링크 누락 | 다음을 확인하지 않음: getInitialLink() |
아래처럼 _appLinks.getInitialLink() 값과 일치해야 해요. 기준은 initState |
| 디버그에서는 되지만 릴리스에서는 안 됨 | assetlinks.json의 지문이 잘못됨 | 릴리스 키 지문(또는 Play 앱 서명 지문) 추가 |
| 딥 링크가 한 번만 동작하고 멈춤 | Activity가 재사용되지 않고 다시 생성됨 | 설정: android:launchMode="singleTop" |
| 쿼리 파라미터 누락 | 파서가 쿼리 문자열을 제거함 | 가능하면 uri.queryParameters 로 접근 |
디버그 로그
로그를 추가해서 딥 링크 흐름을 추적해 보세요:
void _handleDeepLink(Uri uri) {
debugPrint('Deep link received: $uri');
debugPrint('Path: ${uri.path}');
debugPrint('Query: ${uri.queryParameters}');
// ... 라우팅 로직
}
여러 경로 프리픽스
딥 링크 경로가 많다면 Intent 필터에서 성격별로 묶어 주세요:
<!-- 제품 관련 링크 -->
<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="yourdomain.com"
android:pathPrefix="/products" />
<data android:scheme="https"
android:host="yourdomain.com"
android:pathPrefix="/categories" />
</intent-filter>
<!-- 사용자 관련 링크 -->
<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="yourdomain.com"
android:pathPrefix="/referral" />
<data android:scheme="https"
android:host="yourdomain.com"
android:pathPrefix="/offers" />
</intent-filter>
참고: 여러 개의 <data> 요소를 하나의 <intent-filter>안에 쓸 수 있어요. Android는 scheme, host, pathPrefix를 모든 <data> 요소에 나열된 모든 HTTPS 도메인을 검증해요.
Flutter Android용 Tolinku
Tolinku 는 assetlinks.json 파일을 자동으로 호스팅해요. Android 패키지 이름과 서명 키 지문을 Appspace 설정에서 설정하면 assetlinks.json이 생성되어 도메인에서 제공돼요. Flutter SDK 는 디퍼드 딥 링킹과 분석을 제공해요.
Flutter 전체 설정은 다음을 참고하세요: Flutter의 App Links: Android 설정 가이드. 크로스 플랫폼 개요는 다음 글을 참고하세요: 2026년 크로스 플랫폼 딥 링킹 가이드.
딥 링킹 팁을 메일로 받아 보세요
일주일에 한 번만 보내요. 스팸은 없어요.