intent URL의 AndroidManifest.xml 파일은 Android 앱 딥 링크 설정의 시작점이에요. 앱이 처리해야 하는 모든 URL, 매칭해야 하는 모든 경로 패턴, 그리고 App Links 검증을 켜는 autoVerify 플래그가 모두 여기에 있어요. 이 설정을 제대로 해야 Android App Links가 동작해요.
이 튜토리얼은 단일 액티비티 기본 설정부터 여러 액티비티와 경로 패턴을 쓰는 복잡한 설정까지, 관련된 요소와 속성을 하나씩 짚어 가요.
Android의 딥 링크 라우팅 방식
사용자가 URL을 탭하면 Android는 설치된 앱 중 그 URL 처리를 선언한 앱을 확인해요. 이 매칭은 intent filter로 이뤄지고, intent filter는 AndroidManifest.xml XML 선언으로, 액티비티가 처리할 수 있는 URL, 스킴, 호스트, 경로를 시스템에 알려 줘요.
커스텀 URI 스킴(예: myapp://)에서는 어떤 앱이든 어떤 스킴이든 선언할 수 있어요. HTTPS App Links는 검증 단계가 추가되어서, 시스템이 https://yourdomain.com/.well-known/assetlinks.json 을 가져와서 앱이 그 도메인 URL을 처리할 권한이 있는지 확인해요. 이렇게 하면 다른 앱이 URL을 가로챌 수 없어요.
Android 공식 문서 중 앱 콘텐츠로 딥 링크 만들기 편에서 라우팅 방식을 자세히 다뤄요. 그리고 App Links 검증 문서에서 검증 흐름을 다뤄요.
Intent Filter 구조
딥 링크 intent filter는 <activity> 요소 안에 넣어요. 단일 HTTPS URL을 처리하는 최소 설정은 다음과 같아요:
<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="yourdomain.com" />
</intent-filter>
</activity>
모든 App Links intent filter에는 정확히 다음 세 가지 요소가 필요해요: <action> 와 <category> 이 요소들은 필수예요:
android.intent.action.VIEWAndroid에 이 필터가 뷰 인텐트(탭한 링크, 프로그램으로 여는 경우)를 처리한다고 알려줘요android.intent.category.DEFAULT액티비티를 암시적 인텐트로 시작할 수 있게 해줘요android.intent.category.BROWSABLE브라우저나 다른 웹 이동 상황에서 인텐트가 실행될 수 있게 해줘요
생략한 경우: BROWSABLE, Android가 브라우저나 다른 앱에서 탭한 링크를 액티비티로 연결하지 않아요. 이 설정이 없으면 DEFAULT, 암시적 인텐트 라우팅이 동작하지 않아요. 둘 다 필요해요.
intent URL의 data 요소 상세 설명
intent URL의 <data> 이 요소는 필터가 매칭할 URL을 정해요. 여러 속성을 받아요:
| 속성 | 목적 | 예시 |
|---|---|---|
android:scheme |
URL 스킴 | https 또는 http |
android:host |
도메인 이름 | yourdomain.com |
android:pathPrefix |
문자열로 시작하는 경로 매칭 | /products |
android:path |
정확히 일치하는 경로 매칭 | /about |
android:pathPattern |
정규식과 비슷한 패턴으로 경로 매칭 | /products/.* |
android:pathSuffix |
문자열로 끝나는 경로 매칭 | .pdf |
android:port |
포트 번호 (거의 필요 없음) | 8080 |
대부분의 운영 앱에서는 주로 android:pathPrefix 을 써요. 문자열로 시작하는 경로를 모두 매칭하므로 대부분의 라우트 구조를 다룰 수 있어요.
모든 상품 페이지를 위한 필터는 이런 모습일 수 있어요:
<data
android:scheme="https"
android:host="yourdomain.com"
android:pathPrefix="/products" />
이 설정은 다음과 일치해요: https://yourdomain.com/products, https://yourdomain.com/products/123, https://yourdomain.com/products/category/shoes, 그리고 같은 문자열로 시작하는 다른 모든 경로도 매칭해요. /products.
경로 패턴
android:pathPattern 제한된 패턴 문법을 써요. 그중 . 문자는 임의의 한 문자와 일치하고, .* 는 임의의 문자 연속과 매칭돼요. 그 밖의 정규식 기능은 지원하지 않아요.
<!-- /order/12345 매칭, /order/history 제외 -->
<data
android:scheme="https"
android:host="yourdomain.com"
android:pathPattern="/order/[0-9]*" />
주의할 점은 pathPattern패턴이 부분 문자열이 아니라 경로 전체와 맞아야 한다는 거예요. 다음 경로를 매칭하고 싶다면 /products/anything라면 /products/.*로 보내고, 이렇게 보내면 안 돼요: /products.
참고로 .* Android의 pathPattern 패턴 문법은 표준 정규식이 아니에요. 그중 . 는 모든 문자와 매칭돼요 (슬래시 포함 /), 그래서 /products/.* 는 /products/shoes/sneakers 을 예상대로 매칭해요.
intent URL의 autoVerify 속성
intent URL의 android:autoVerify="true" 속성은 <intent-filter> 요소가 일반 딥 링크 대신 App Links를 켜요. 이 속성이 있으면 Android가 앱의 도메인 소유권을 확인하려고 assetlinks.json 파일을 가져와요.
<intent-filter android:autoVerify="true">
...
</intent-filter>
검증에 성공하면 다음이 적용돼요:
- 앱이 선언한 URL의 기본 핸들러가 돼요
- 매칭되는 URL을 탭하면 선택 창 없이 앱이 바로 열려요
- 사용자에게 앱과 브라우저 중 하나를 고르라고 묻지 않아요
검증이 실패하거나 autoVerify 없으면:
- 일치하는 URL은 일반 딥 링크처럼 동작해요
- 안드로이드에서는 앱과 브라우저 중 하나를 선택하라는 대화상자가 뜰 수 있어요
- 안드로이드 12 이상에서는 검증되지 않은 링크가 기본적으로 브라우저에서 열려요
App Links 검증은 설치 시점에 확인해요. 만약 assetlinks.json 에 접근할 수 없으면 설치할 때 검증이 실패해요. 시스템이 주기적으로 다시 시도하지만, 설정을 고친 뒤에는 검증이 성공하기까지 지연이 있을 수 있어요.
에 대한 자세한 내용은 assetlinks.json 자체의 생성 및 검증 방법을 포함해 다음 가이드에서 다뤄요: assetlinks.json 생성기 가이드.
intent URL의 exported 속성 속성
안드로이드 12(API 레벨 31)부터는 android:exported 속성이 인텐트 필터를 포함하는 모든 액티비티에 필수예요. target SDK가 31 이상인데 이 속성을 빼면 exported 속성빌드가 실패해요.
딥 링크를 처리하는 액티비티(정의상 외부 소스에서 인텐트를 받아야 하는)의 경우, exported 속성 반드시 true여야 해요 true:
<activity
android:name=".MainActivity"
android:exported="true">
외부 인텐트를 받을 필요가 없는 액티비티는 android:exported="false"를 쓰세요. 딥 링크 인텐트 필터가 있는 액티비티만 이 속성이 필요해요. true.
경로별 여러 Intent Filter
하나의 액티비티에 인텐트 필터를 여러 개 추가할 수 있어요. 각 필터는 독립적으로 평가돼요. 서로 다른 액티비티로 보내지 않고 액티비티 코드에서 처리하고 싶다면, 서로 다른 URL 경로를 같은 액티비티로 보내는 올바른 방법이에요.
<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="yourdomain.com"
android:pathPrefix="/products" />
</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="/orders" />
</intent-filter>
</activity>
autoVerify를 설정한 각 인텐트 필터는 autoVerify="true" 서로 독립적이에요. 검증은 인텐트 필터마다 수행되지만, 실제로는 시스템이 도메인 전체를 한 번에 검증해요.
여러 액티비티로 라우팅
앱이 큰 경우, URL 패턴마다 다른 액티비티를 열고 싶을 수 있어요. 각 액티비티가 자신만의 인텐트 필터 세트를 가져요:
<!-- 제품 상세 액티비티 -->
<activity
android:name=".ProductDetailActivity"
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="yourdomain.com"
android:pathPattern="/products/.*" />
</intent-filter>
</activity>
<!-- 사용자 프로필 액티비티 -->
<activity
android:name=".ProfileActivity"
android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="yourdomain.com"
android:pathPrefix="/u" />
</intent-filter>
</activity>
두 인텐트 필터가 같은 URL에 모두 맞을 수 있으면, 안드로이드는 가장 구체적인 매칭을 골라요. 더 구체적인 것이 경로 보다 우선하고 pathPrefix, 이것은 pathPattern보다 우선해요. 구체성이 같으면 동작이 정의되지 않으니, 패턴이 겹치지 않게 유지하세요.
HTTP와 HTTPS 처리
App Links는 HTTPS만 지원해요. 하지만 HTTP http:// URL(오래된 링크나 리다이렉트용)도 처리하고 싶을 수 있어요. 같은 인텐트 필터에 여러 <data> 요소를 추가하면 두 스킴을 모두 처리할 수 있어요:
<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" />
<data android:scheme="http" android:host="yourdomain.com" />
</intent-filter>
중요: autoVerify autoVerify는 HTTPS 스킴에만 적용돼요. HTTP URL은 검증되지 않아요. 둘 다 넣으면 HTTP 필터는 일반 딥 링크처럼 동작해서(선택 대화상자나 브라우저 대체 동작이 붙어요), HTTPS 필터만 검증의 혜택을 받아요.
여러 호스트와 서브도메인
여러 도메인의 URL을 처리해야 한다면(예: 둘 다 yourdomain.com 와 www.yourdomain.com), 별도의 <data> 요소를 추가하거나 인텐트 필터를 따로 쓰세요:
<data android:scheme="https" android:host="yourdomain.com" />
<data android:scheme="https" android:host="www.yourdomain.com" />
선언하는 호스트마다 각각 assetlinks.json 검증이 필요해요. 만약 www.yourdomain.com 을 매니페스트에 선언하고 호스팅하지 않으면 assetlinks.json 두고 있는지 https://www.yourdomain.com/.well-known/assetlinks.json (또는 올바르게 리다이렉트하지 않으면) 해당 호스트의 검증은 실패해요.
안드로이드 12부터 와일드카드 호스트 매칭이 가능해요. 다음 값을 쓰면 *.yourdomain.com 로 모든 서브도메인에 매칭할 수 있어요:
<data android:scheme="https" android:host="*.yourdomain.com" />
와일드카드 호스트 매칭을 쓰려면 유효한 assetlinks.json 검증하려는 서브도메인마다 파일이 있어야 하거나, 적절한 include 구문으로 루트 도메인에서 검증을 처리해야 해요. 이 과정은 Android App Links 검증 문서 에서 와일드카드 검증 과정을 자세히 다뤄요.
액티비티에서 인텐트 읽기
Android가 URL을 액티비티로 연결하면, 그 URL을 읽고 알맞은 콘텐츠로 이동해야 해요. Kotlin에서는 이렇게 해요:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val intent = intent
val action = intent.action
val data: Uri? = intent.data
if (Intent.ACTION_VIEW == action && data != null) {
val path = data.path
val params = data.queryParameterNames
// 경로에 따라 라우팅
when {
path?.startsWith("/products/") == true -> {
val productId = path.removePrefix("/products/")
navigateToProduct(productId)
}
path?.startsWith("/orders/") == true -> {
val orderId = path.removePrefix("/orders/")
navigateToOrder(orderId)
}
else -> navigateToHome()
}
}
}
앱에서 Jetpack Navigation을 쓰고 있다면 딥 링크 연동 을 쓰면 경로를 직접 파싱하지 않고, 내비게이션 그래프에서 라우팅을 선언적으로 처리할 수 있어요.
Manifest 설정 테스트
Android는 adb intent filter 매칭을 실제 링크를 누르지 않고 테스트할 수 있는 명령줄 도구를 제공해요:
adb shell am start \
-W -a android.intent.action.VIEW \
-d "https://yourdomain.com/products/123" \
com.yourapp.package
이 명령은 VIEW 인텐트를 앱에 직접 보내고, 어느 액티비티가 처리했는지 알려줘요. 경로 패턴이 기대한 URL과 맞는지 확인할 때 유용해요.
App Links 검증만 따로 테스트하려면 이 명령을 쓰세요:
adb shell pm get-app-links com.yourapp.package
이 명령은 앱에 선언된 도메인마다 검증 상태를 보여줘요. 상태가 verified 이면 App Links가 정상 동작해요. 다른 상태라면 검증이 성공하지 못한 것이라서 링크는 브라우저 방식으로 열려요.
매니페스트 설정을 링크 라우팅 및 분석에 연결하는 Tolinku 플랫폼 설정은 Android 설정 가이드 및 App Links 개발자 문서.
Android App Links가 매니페스트 밖에서 전체적으로 어떻게 동작하는지 알고 싶다면 참고할 곳은 Android App Links 완벽 가이드.
딥 링킹 팁을 메일로 받아 보세요
일주일에 한 번만 보내요. 스팸은 없어요.