Sub topic 12
Testing deep links with adb and simctl
Deep links are hard to test by tapping, because you would need a real message or web page for each link. The command-line tools adb (Android) and xcrun simctl (iOS simulator) send a link straight to a device. This chapter shows how to use them to check routing, startup states, and domain verification.
It assumes you have configured the Android intent filter and assetlinks.json, the iOS Associated Domains entitlement and apple-app-site-association file, and a go_router setup from earlier chapters. You also need an emulator or device with adb on your path, and a Mac with Xcode for the simulator commands.
What you are testing
Three separate things can fail, and each needs a different check:
- Routing: the app receives the URL and maps it to the right screen.
- Startup state: the link works when the app is closed (cold start) and when it is already running (warm start).
- Verification: the operating system trusts your domain and opens the app directly, without a chooser or a browser.
Command-line delivery tests the first two easily. Verification needs extra commands, covered below.
Sending a link on Android
The basic command sends a VIEW intent with your URL as its data:
# Android (emulator or device)
adb shell am start -a android.intent.action.VIEW \
-d "https://example.com/products/42" com.example.app
# iOS simulator
xcrun simctl openurl booted "https://example.com/products/42"The Android command has three parts. -a sets the action, -d sets the data (the URL), and the final argument restricts the intent to one package. The booted argument in the iOS command means "the simulator that is currently running".
Quote query strings correctly
The adb shell command passes your text to a shell on the device. An unquoted & in a URL ends the command there, and the rest is run as a separate command in the background. Wrap the whole remote command in double quotes and the URL in single quotes:
adb shell "am start -a android.intent.action.VIEW \
-d 'https://example.com/products/42?ref=email&campaign=spring' com.example.app"If your route reads campaign and it is always null, this quoting problem is the first thing to check.
The package argument hides verification problems
When you name the package, Android delivers the intent to that app whether or not the domain is verified. A successful run therefore proves your routing works. It does not prove that a link tapped in a messaging app will open your app.
To see what a user would get, run the command once without the package:
adb shell am start -a android.intent.action.VIEW \
-d "https://example.com/products/42"If verification worked, the app opens directly. If it did not, you see a chooser or the browser opens.
Sending a link on iOS
simctl openurl works with custom schemes and HTTPS links:
xcrun simctl openurl booted "myapp://products/42"
xcrun simctl openurl booted "https://example.com/products/42?ref=email"Custom-scheme links are the most reliable way to test routing on the simulator. HTTPS links depend on the system having fetched and accepted your apple-app-site-association file. If an HTTPS link opens Safari instead of your app, check the file first (see below) and test the routing with a custom scheme in the meantime.
For a physical iPhone there is no simctl. Paste the link into Notes and tap it, or use the ?mode=developer suffix on the associated domain entry (applinks:example.com?mode=developer) in debug builds so the device fetches the file directly instead of through Apple's cache.
Cold start and warm start
Each link should be tested in both states, because the app receives it by different routes. Cold start means the process is not running. Warm start means it is running in the foreground or background.
The following sequence tests both on Android:
# Cold start: kill the process, then open the link
adb shell am force-stop com.example.app
adb shell am start -a android.intent.action.VIEW \
-d "https://example.com/products/42" com.example.app
# Warm start: launch the app normally, then send a different link
adb shell monitor --version >/dev/null 2>&1
adb shell am start -n com.example.app/.MainActivity
adb shell am start -a android.intent.action.VIEW \
-d "https://example.com/products/7" com.example.appOn iOS, use terminate for the cold case:
xcrun simctl terminate booted com.example.app
xcrun simctl openurl booted "https://example.com/products/42"Common results:
| What you see | Likely cause |
|---|---|
| Cold start shows the home screen, warm start shows the product | The initial link is ignored. Check `initialLocation` and any manual `app_links` setup. |
| Warm start opens a second copy of the product screen | The route uses `push` rather than `go`, or the activity launch mode creates a new instance. |
| Both states show the unknown-link screen | The path does not match any route. |
Making the router tell you what it received
Turn on router logging in debug builds so you can see the URL that arrived:
import 'package:go_router/go_router.dart';
final router = GoRouter(
debugLogDiagnostics: true,
routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomeScreen(),
),
GoRoute(
path: '/products/:id',
builder: (context, state) =>
ProductScreen(id: state.pathParameters['id']!),
),
],
);Run the app with flutter run and send a link. The console prints the matched location. If nothing prints, the link never reached Flutter, and the problem is in the platform configuration, not the router. On Android, adb logcat -s ActivityManager shows which activity received the intent.
Checking verification
Android
Android 12 and later records the verification result for each domain. Ask for it:
adb shell pm get-app-links com.example.appEach domain in your intent filter is listed with a state. verified is what you want. Other states, such as none or a failure code, mean Android could not validate the domain.
To retry after fixing your server file:
adb shell pm verify-app-links --re-verify com.example.appVerification runs asynchronously, so wait a few seconds and run get-app-links again. Also fetch the file the way Android would:
curl -i https://example.com/.well-known/assetlinks.jsonIt must return status 200 over HTTPS with no redirect, and the package_name and certificate fingerprint must match the build you installed. A debug build and a release build are signed with different certificates, so the fingerprint for one will not verify the other.
iOS
Fetch the association file and check three things: the status is 200, no redirect occurs, and the content type is JSON.
curl -i https://example.com/.well-known/apple-app-site-associationThen confirm that the appIDs value is your team ID followed by the bundle ID, and that the applinks:example.com entry is present in Xcode under Signing & Capabilities. A changed file may not take effect immediately, because iOS caches it. Deleting and reinstalling the app on the simulator or device prompts a new fetch.
A debugging path
The diagram shows the order in which to rule out causes.
Edge cases to test
- Trailing slash: send
/products/42/as well as/products/42. Decide whether both should match. - Missing or extra parameters: send
/products/and/products/42?ref=. - Encoded characters: send
/products/a%20band confirm the value is decoded once. - Signed-out user: send a protected link while logged out and confirm that you are redirected to login and then returned to the original page.
- Unexpected host: send
https://evil.example/products/42with the package argument and confirm your handler ignores it.
Exercise
You run adb shell am start -a android.intent.action.VIEW -d "https://example.com/products/42?ref=email&campaign=spring" com.example.app and your product screen shows ref as email but campaign as null. Why, and how do you fix the command?
Show answer
The & is interpreted by the shell on the device, so the command ends before campaign=spring and the rest runs as a separate background command. Wrap the whole remote command in double quotes and the URL in single quotes: adb shell "am start -a android.intent.action.VIEW -d 'https://example.com/products/42?ref=email&campaign=spring' com.example.app".
Exercise
A link opens your app when you send it with the package name, but a user who taps the same link in a chat app sees a browser. Which two commands do you run first, and what do you look for?
Show answer
Run adb shell pm get-app-links com.example.app and look for verified next to your domain. Run curl -i https://example.com/.well-known/assetlinks.json and check for status 200 with no redirect and a package name and fingerprint that match the installed build. The package argument bypasses verification, so the first test passed while verification failed.