Search code examples
androidflutterdeep-linkinggorouter

Flutter deep linking using gorouter plugin not working to redirect from webapp to Android app


I've put deep linking into my app. If I launch links of the form:

https://edinburgh-guide-airbnb.web.app/Leith

It successfully strips the appendix out and opens the user in the correct place in my web app. But I want to be able to share URLs with users, if they have a native app it should open that using the deep link's instruction, if they don't then it should FALLBACK to my web app.

I've read the Flutter's deep link docs and added this to my manifest.xml:

    </intent-filter>
    <!-- Deep linking -->
    <meta-data android:name="flutter_deeplinking_enabled" android:value="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="http" />
        <data android:scheme="https" />
        <data android:host="edinburgh-guide-airbnb.web.app" />
    </intent-filter>

I believe this should hijack any URL with a body of edinburgh-guide-airbnb.web.app. It doesn't 😭

I think my manifest must be at fault because the URL never triggers my installed native app, it doesn't even try to process the deep-link, instead Android skips straight to the web app. Which I don't think concerns itself with the manifest.xml file.

Is my manifest.xml formatted incorrectly? Am I misunderstanding how to intercept the link above^?

For completeness here is how my app processes deep links in my main.dart, using Flutter's goRouter plugin

final GoRouter _router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        return MyHomePage(title: "", analytics: analytics, observer: observer);
      },
      routes: <RouteBase>[
        GoRoute(
          path: 'leith',
          builder: (BuildContext context, GoRouterState state) {
            return MyHomePage(title: "Leith", analytics: analytics, observer: observer);
          },
        ),
      ],
    ),
  ],
);

Solution

  • You need to have correct assetlinks.json at https://edinburgh-guide-airbnb.web.app/.well-known/assetlinks.json with

    • app package name
    • signing fingerprint