Flutterfire: [firebase_dynamic_links] onLink never triggered for Android

Created on 26 May 2020  Â·  7Comments  Â·  Source: FirebaseExtended/flutterfire

firebase_dynamic_links: 0.5.0+11

I'm not sure if this is a bug or not, but when using Firebase Dynamic Links on Android, I always receive it with getInitialLink and never onLink. As mentioned here, I delay my initial call with a Timer because otherwise getInitialLink is always null. But that is not the problem I'm focused on in this issue.

On iOS, I am seeing both getInitialLink and onLink give me the dynamic link in the respective situations I'd expect (initial app launch versus when the app is already running). However, on Android if I tap a link from Gmail or a note, it correctly opens the app, but it's always finding the link with getInitialLink and never the onLink handler.

Is this incorrect behavior, or is onLink just for iOS, or is something else going on?

  @override
  void initState() {
    super.initState();
    _timerLink = new Timer(const Duration(milliseconds: 700), () {
      print('700 ms later, going to init dynamic links');
      this.initDynamicLinks();
    });
  }

  void initDynamicLinks() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
    final Uri deepLink = data?.link;

    if (deepLink != null) {
      //Navigator.pushNamed(context, deepLink.path);
      print('\n\n got initialLink: $deepLink \n\n');
    } else {
      print('\n\n deepLink from getInitialLink is null and $data \n\n');
    }

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
          final Uri deepLink = dynamicLink?.link;

          if (deepLink != null) {
            //Navigator.pushNamed(context, deepLink.path);
            print('\n\n got onLink: $deepLink \n\n');
          } else {
            print('\n\n onLink fired but deepLink was null \n\n');
          }
        },
        onError: (OnLinkErrorException e) async {
          print('onLinkError');
          print(e.message);
        }
    );
  }

flutter doctor -v
[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.4 19E287, locale en-US)
    • Flutter version 1.17.1 at /Users/stephen/wardrobe/flutter
    • Framework revision f7a6a7906b (13 days ago), 2020-05-12 18:39:00 -0700
    • Engine revision 6bc433c6b6
    • Dart version 2.8.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/stephen/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    ! CocoaPods 1.7.5 out of date (1.8.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade:
        sudo gem install cocoapods

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.8052
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.45.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.2

[✓] Connected device (2 available)
    • Nokia 6 1                  • PL2GARM870103356                     • android-arm64 • Android 10 (API 29)
    • iPhone SE (2nd generation) • 45D76A5A-C10A-42B7-9753-51B3B0DF66B9 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-5 (simulator)

! Doctor found issues in 1 category.

dynamic_links bug

All 7 comments

Interesting, I have the same problem on iOS, but Android works fine.

Fascinating! On iOS I've been testing on an iPhone 11, though it seems like the only thing that matters would be the Android or iOS version.

It'd be great if Flutter has easy and consistently behaving dynamic links because one of Flutter's selling points is that it's cross-platform and Firebase Dynamic Links are a great way to easily communicate across Android and iOS.

Problem resolved. I generate the dynamic links manually from the server. Concatenating all the parameters into a string as a dynamic link works fine for Android.
For iOS, it needs to use the Uri parse to process the link parameter.

Interesting, @SeanZom - seems like that should not affect me when generating the DynamicLinkParameters parameters in Dart on the mobile device. I use Uri.parse there too as shown here and on iOS I'm seeing the fully expanded link in the clipboard after tapping the dynamic link. I mean, it has the expected parameters such as apn, amv, isi, etc. For some reason I don't see that on Android but that's probably a difference from iOS. My app is not yet published in either store but the Apple App Store lets me click the Open button to resolve the dynamic link.

Anyway, eventually I'm able to get the dynamic link in Android since getInitialLink has it after a delay, even when it should be onLink.

FYI, onLink is successfully obtaining the link on both iOS and Android in the latest version:

firebase_dynamic_links 0.5.3

Actually, now I'm having trouble again, and this time it's specifically Android not ever using onLink. iOS is correctly using getInitialLink on startup and onLink for other cases, but on Android it's always firing getInitialLink for some strange reason!

My pubspec.lock is showing firebase_dynamic_links 0.6.0+2 now and I just forced a downgrade to 0.6.0 to make sure there wasn't a recent regression. And this coupled with the fact that the dynamic link does not get cleared as mentioned in this mysteriously locked and limited issue leads to some wonky behavior. Hopefully these 2 issues will be fixed soon!

[✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.7 19H2, locale en-US)
• Flutter version 1.22.0 at /Users/stephen/wardrobe/flutter
• Framework revision d408d302e2 (3 weeks ago), 2020-09-29 11:49:17 -0700
• Engine revision 5babba6c4d
• Dart version 2.10.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/stephen/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0.1, Build version 12A7300
• CocoaPods version 1.9.3

[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 50.0.1
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.50.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.15.1

[✓] Connected device (2 available)
• Nokia 6 1 (mobile) • PL2GARM870103356 • android-arm64 • Android 10
(API 29)
• Roisin (mobile) • 00008030-000139113A30802E • ios • iOS 14.0.1

• No issues found!

Was this page helpful?
0 / 5 - 0 ratings