Sub topic 7
Setting up Android App Links
This chapter covers the Android side of verified HTTPS deep links. It assumes you know what a deep link is, you can read a URI (scheme, host, path, query), and you can build and run a Flutter app on an Android emulator or device. You also need a domain you control, where you can publish a file under /.well-known/. The chapter covers three things: how Android decides that your app owns a domain, the two pieces of configuration that prove it, and how to debug verification when it fails.
What makes an App Link different
A custom scheme such as myapp://products/42 works without any proof. Any app can claim it, so Android may show a chooser or open the wrong app. An Android App Link is an https:// link that Android opens directly in your app without a prompt. Android only does this after it has confirmed that the website owner and the app developer are the same party.
That confirmation needs two pieces:
- An intent filter in your app that declares which URLs it can handle and asks for verification.
- A Digital Asset Links file,
assetlinks.json, on your domain that names your app and its signing certificate.
If either piece is missing or wrong, the link still works as an ordinary web link and opens in the browser. Nothing crashes. This silent fallback is why most App Link problems are discovered late.
Step 1: Add the intent filter
Open android/app/src/main/AndroidManifest.xml. Inside the <activity> element for MainActivity, next to the existing MAIN/LAUNCHER filter, add a second 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="example.com" android:pathPrefix="/products" />
</intent-filter>Each part has a job:
android:autoVerify="true"asks Android to check the domain's Asset Links file. Without it, the link is never verified.- The
VIEWaction says the activity can display the data in the URL. BROWSABLEallows a link tapped in a browser, email, or message to start the activity.DEFAULTlets the activity receive implicit intents. Links will not resolve without it.- The
dataelement restricts the filter tohttpslinks onexample.comwhose path starts with/products.
Keep this filter separate from the launcher filter. Do not add autoVerify to the MAIN/LAUNCHER filter.
Matching rules to watch
Android offers several path attributes. Choose the narrowest one that works.
| Attribute | Matches | Example |
|---|---|---|
| `android:path` | The exact path | `/products` |
| `android:pathPrefix` | Any path that starts with the value | `/products` matches `/products/42` |
| `android:pathPattern` | A simple glob using `.*` | `/products/.*` |
| `android:pathAdvancedPattern` | A richer regex-like syntax (API 31 and later) | `/products/[0-9]+` |
Two behaviors cause many surprises:
- The host must match exactly.
example.comandwww.example.comare different hosts, and each needs its owndataelement and its own verified file. - Android combines every
dataelement inside one intent filter into all possible scheme, host, and path combinations. If you need different paths on different hosts, use separate intent filters.
For Flutter, MainActivity normally already has android:launchMode="singleTop". Keep it. It makes a link tapped while the app is open reuse the existing activity instead of stacking a new one.
Step 2: Let Flutter receive the link
Recent Flutter versions have deep linking enabled by default, so the platform hands the link to the framework and the router handles it. Older projects needed this inside the <activity> element:
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />If you use a package such as app_links and handle links yourself, you can turn Flutter's built-in handling off with the same key set to false. Otherwise both Flutter and your code may react to one link. If you are unsure which behavior your Flutter version has, check its deep linking documentation before deciding.
Step 3: Publish assetlinks.json
Create the file and serve it at exactly this address:
https://example.com/.well-known/assetlinks.json[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.app",
"sha256_cert_fingerprints": ["<SHA256_FINGERPRINT_OF_SIGNING_CERT>"]
}
}
]package_name must equal your applicationId in android/app/build.gradle. The fingerprint is the SHA-256 hash of the certificate that signed the installed build. Get it for your keystore with:
keytool -list -v -keystore my-release-key.jks -alias my-key-aliasCopy the SHA256: line. Keep the colon-separated uppercase hex format.
Your server must meet these requirements:
- It serves the file over HTTPS with a valid certificate.
- The response is
200 OKwith a JSON content type. - There are no redirects. A redirect from
httptohttps, or from the bare domain towww, can break verification. - No login, cookie, or IP restriction protects the file, because Android's verifier fetches it anonymously.
robots.txtdoes not block it.
Which certificate signs your app?
This is the most common cause of "works in debug, fails in production."
- A debug build is signed with your local debug keystore, so its fingerprint differs from the release one.
- If you use Play App Signing, Google re-signs the app you upload. The users' installed app carries Google's app signing certificate, not your upload key. Copy the fingerprint from Play Console under Setup, App signing.
The sha256_cert_fingerprints array can hold several fingerprints. List the debug, upload, and Play signing fingerprints during development so that every build variant verifies. Remove the debug fingerprint from the production file if you do not want debug builds to verify.
Step 4: Check verification
Verification runs at install time and again later at intervals, so after you change assetlinks.json you must trigger it yourself. On Android 12 and later, use these commands:
# Ask the system to check the domain again
adb shell pm verify-app-links --re-verify com.example.app
# Read the result per domain
adb shell pm get-app-links com.example.appIn the output, look for your domain with the state verified. Other states, such as none or a failure code, mean Android could not confirm ownership. Android 12 also lets the user override this in system settings under App info, Open by default, so check there if the state says verified but links still open in the browser.
Then send a link to the device, as described in the testing chapter:
adb shell am start -a android.intent.action.VIEW \
-d "https://example.com/products/42" com.example.appPassing the package name forces this app to handle the link and skips the verification question. A true test is tapping the same URL in a message or the browser address bar. Do both.
Common errors
| Symptom | Likely cause |
|---|---|
| Link opens in the browser | Verification failed or `autoVerify` is missing |
| Works on debug, not on Play install | Play signing fingerprint missing from the JSON |
| Fails only on `www.example.com` | No `data` element or file for that host |
| Verification state stays `none` | File not reachable, redirected, or wrong content type |
| App opens but shows the home screen | The link arrived, but the router has no matching route |
| A chooser dialog appears | The domain is not verified, and another app handles the same URL |
When the app opens on the wrong screen, verification is not the problem. Check your router configuration, which the next chapters cover.
Exercise
Your App Link works when you install a debug build from Android Studio, but users who install from Google Play get the browser instead. The intent filter and autoVerify are identical in both builds. What do you check, and what do you change?
Show answer
Check which certificate signs the Play build. With Play App Signing, Google re-signs the app, so its SHA-256 fingerprint is the app signing certificate shown in Play Console, not your local debug or upload key. Add that fingerprint to the sha256_cert_fingerprints array in assetlinks.json, confirm the file is served over HTTPS with no redirect, then reinstall the Play build or run adb shell pm verify-app-links --re-verify com.example.app and confirm the state with adb shell pm get-app-links com.example.app.
Exercise
You support both example.com and www.example.com. What must exist for both hosts to open in the app?
Show answer
The manifest needs a data element for each host (in the same filter if the scheme and path are shared). Each host must also serve its own assetlinks.json at /.well-known/assetlinks.json with no redirect, because Android verifies each host separately.