Search code examples
androiddeep-linking

Android deep links - allow use of subdomain URLs, with assetlinks.json on organizational domain?


I've used Android App Studio's App Links Assistant to map my URL to MainActivity.kt, and I can click a link in an email to open my app in the simulator.

The URL mapping when declared exactly, e.g. https://myorg.com/open-in-app, opens the app as desired.

If I pass my email through an email service that implements link wrapping with HTTPS, I have to use a subdomain. So, for example wrapped link can look like

https://track.myorg.com/open-in-app/xyzzy

In iOS / Xcode, I can set up multiple domain associations for a given app, with wildcards for subdomains as described here. iOS fetches the apple-app-site-association file from the subdomain's, or the organizational domain's /.well-known path. Apple recommends the org domain in the first instance here, which is handy for supporting the same app on multiple subdomains.

Note: It's possible to host the assetlinks.json file on the subdomain, but it's a bit more complex to do this (e.g. using a CDN). https://track.myorg.com usually maps to the email service, which returns a redirect to the landing page. For everyone not using the app, the link will open in their browser.

In Android, is there an equivalent, i.e. host the assetlinks.json file in one place - on the org domain - and still deep link to URLs with subdomains?


Solution

  • Testing on the Android Studio simulator, device Pixel 2, Android API level 30.

    assetlinks.json file can be picked up from the organizational domain of a link, or from the actual (sub-domain) of a link.

    The sub-domain also works via a 301 redirect, which is necessary for some CDNs such as CloudFlare. Others (such as AWS CloudFront) can host the files directly.

    See also: this article