# Testing & Troubleshooting

Testing deferred linking on Android has platform constraints, mainly around install referrer availability and app-link verification state.

## Deferred flow constraints

- Deferred matching is intended for first-launch flow after install.
- Deterministic matching uses Play Install Referrer `click_id` when available.
- If install referrer is unavailable, SDK falls back to probabilistic matching.
- Repeated deferred attempts in same install/session return `NotFirstLaunch`.

## Recommended deferred test flow

1. Uninstall the app from the device or emulator.
2. Open a Detour link in a browser.
3. Install and launch the app.
4. Verify `LinkResult.Success` with `type = DEFERRED`, or expected fallback (`NoLink` / `Error`).
5. Relaunch the app and confirm the deferred link is not consumed again, that is `LinkResult.NotFirstLaunch`.

:::note[Missing `click_id`]
If you encounter click_id missing in your build see limitations section [Play Store referrer missing](https://detour.swmansion.com/docs/platform/architecture/architecture-limitations#play-store-referrer-missing)
:::

## Testing app links and scheme links

For app-link/scheme integration (`LinkProcessingMode.ALL`), verify both cold and warm starts.

### App Link via ADB

```bash
adb shell am start -a android.intent.action.VIEW \
  -d "https://<your-link-domain>/products/42" \
  <your.package.name>
```

Expected: `LinkResult.Success` with `type = VERIFIED`.

### Custom scheme via ADB

```bash
adb shell am start -a android.intent.action.VIEW \
  -d "myapp://products/42" \
  <your.package.name>
```

Expected: `LinkResult.Success` with `type = SCHEME` (only when `LinkProcessingMode.ALL`).

### App Link verification and the SHA-256 fingerprint

An `autoVerify` App Link opens your app only if the Dashboard SHA-256 matches the key that signed **the installed APK**:

| How the app is installed                         | Signed with                | Where to read the SHA-256                                                                               |
| :----------------------------------------------- | :------------------------- | :------------------------------------------------------------------------------------------------------ |
| Google Play, any track                           | Play App Signing key       | Play Console → **Protected with Play** → **Manage Play app signing** → *App signing key certificate*    |
| Android Studio run / `./gradlew assembleDebug`   | AGP default debug keystore | `keytool -list -v -keystore ~/.android/debug.keystore -storepass android`, or `./gradlew signingReport` |
| `./gradlew assembleRelease` with your own config | Your release keystore      | `keytool -list -v -keystore <path-to-your.keystore>`, or `./gradlew signingReport`                      |

`./gradlew signingReport` prints the `Store:` path each variant really uses, so it stays correct when a project overrides `signingConfigs.debug`. To check a binary directly: `apksigner verify --print-certs app-debug.apk`.

Then check what the device made of it:

```bash
adb shell pm verify-app-links --re-verify <your.package.name>
adb shell pm get-app-links <your.package.name>   # expect: verified
```

The complete procedure is described in [Finding your Android SHA-256 fingerprint](https://detour.swmansion.com/docs/platform/fundamentals/universal-app-links#finding-your-android-sha-256-fingerprint).

## Troubleshooting checklist

- `Detour SDK not initialized`
  - `Detour.initialize(...)` was not called before `processLink()` / `getDeferredLink()`.
- Immediate `NoLink`
  - no matching click found. Verify the link click happened before install.
- Always `NotFirstLaunch`
  - first-launch flag already stored. Reinstall the app for deferred testing.
- App links open browser instead of app
  - check Dashboard app-link domain config and manifest intent-filter alignment.
  - confirm the Dashboard SHA-256 matches the key that signed the installed APK. See [App Link verification and the SHA-256 fingerprint](#app-link-verification-and-the-sha-256-fingerprint).
- Custom scheme not handled
  - verify manifest `<data android:scheme="...">` and `LinkProcessingMode.ALL`.
- Analytics events not visible
  - ensure valid `apiKey`/`appId` and call `DetourAnalytics` only after SDK initialization.

## Debugging

Use logcat while testing:

```bash
adb logcat | grep -i detour
```

Useful tags from SDK internals:

- `Detour`
- `DetourApiClient`
- `InstallReferrerHelper`
- `DetourAnalytics`

For complete end-to-end sample flows, use [Examples](https://detour.swmansion.com/docs/sdk/android/examples).