firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.62k stars 3.95k forks source link

[dynamic-links] Link generated on IOS not work on Android #7737

Closed azazadev closed 2 years ago

azazadev commented 2 years ago

Problem Description

In my flutter app I'm using firebase_dynamic_links: ^4.0.3 to share posts between users

I don't know if this can be the problem but the generated Link is not the same on Iphone and Android

for example with the same post ID the generated link will be :

EXPECTED : Link should work also on Andoid when it's sent from Iphone

code used to create Link :

  Future<String> createPostLink(String postId) async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    String uriPrefix = "https://myappname.page.link";
    final DynamicLinkParameters parameters = DynamicLinkParameters(
      uriPrefix: uriPrefix,
      link: Uri.parse('https://myappname.app/$postId'),
      androidParameters: AndroidParameters(
        packageName: packageInfo.packageName,
      ),
      iosParameters: IOSParameters(
        bundleId: packageInfo.packageName,
        minimumVersion: packageInfo.version,
        appStoreId: '1528480989',
      ),
    );
    final ShortDynamicLink shortDynamicLink =
        await dynamicLinks.buildShortLink(parameters);
    final Uri shortUrl = shortDynamicLink.shortUrl;
    return shortUrl.toString();
  }

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-x64, locale en-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Android Studio (version 4.0)
[✓] IntelliJ IDEA Community Edition (version 2020.2.1)
[✓] VS Code (version 1.63.0)
[✓] VS Code (version 1.59.0)
[✓] Connected device (4 available)

• No issues found!

please help fixing this issue !!

darshankawar commented 2 years ago

@azazadev Can you provide the entire error log when you try to access the link from ios to android ? Also, while doing so, does getInitialLink() shows any data or is null ?

azazadev commented 2 years ago

Thanks @darshankawar for the quick replay !

I don't know how we can get error because the app is not launched in case of Android

take this simple scenario

NOTE : this code is not executed in case of Andoid so we cannot know if the getInitialLink have data or not

code to handle DynamicLinks

Future handleDynamicLinks() async {
    final PendingDynamicLinkData data = await dynamicLinks.getInitialLink();
    await _handleDeepLink(data);
    dynamicLinks.onLink.listen((dynamicLinkData) async {
      _handleDeepLink(dynamicLinkData);
    }).onError((error) {
      logger.e('Link Failed: ${error.message}');
    });
  }

  Future<void> _handleDeepLink(PendingDynamicLinkData data) async {
    final Uri deepLink = data?.link;
    if (deepLink != null) {
      var isPost = deepLink.pathSegments.length == 1;
      if (isPost && _authenticationService.currentUser != null) {
        var postId = deepLink.pathSegments.first;
        if (postId != null) {
          // postId received successfully !!
        }
      }
    }
  }

please let me know if you need any additional infos

azazadev commented 2 years ago

I'm able to progress on this issue but I'm not convinced about the solution !

Finding

as from documentation we should Add deep link domains in AndroidManifest.xml as below

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data
        android:host="example.com"
        android:scheme="https"/>
</intent-filter>

in my case android:host="myappname.app"

but from this link android:host is equals to the page.link in my case this should be myappname.page.link

so in AndroidManifest.xml I update

from <data android:host="myappname.app" android:scheme="https"/> to <data android:host="myappname.page.link" android:scheme="https"/>

New Test

new bottom sheet menu with :

Complete Action using

myApp Chrome Browser

app is launched and postId is successfully received

NOTE :

so can someone confirm what is the impact of changing the android:host in AndroidManifest.xml from myappname.app to myappname.page.link ? should I go with this change ?

how I can force opening the link with myApp and not with browser ( programmatically because inside the Firebase Console I thik this option exist "Open the deep link in your Android App" ) ?

darshankawar commented 2 years ago

should I go with this change ?

Thanks for the details and updates. According to the official document on setup, it does mention to add the deep link domains to manifest file: https://firebase.flutter.dev/docs/dynamic-links/android-integration#androidmanifestxml-configuration

how I can force opening the link with myApp and not with browser ( programmatically because inside the Firebase Console I thik this option exist "Open the deep link in your Android App" ) ?

If you select app from bottom sheet (shown on some android phones), does it open the app ?

in Firebase console: do you have the same setting as below:

Screenshot 2021-12-31 at 1 56 23 PM

If so, it may be a different issue to tackle and may need to open a new for better tracking.

azazadev commented 2 years ago

If you select app from bottom sheet (shown on some android phones), does it open the app

yes

in Firebase console: do you have the same setting as below

Yes, I check for both I can select my Android app and IOS app

NOTE : we should not forget that link work from

only IPhone to Android we have the issue

azazadev commented 2 years ago

I have try to collect more information, so I create link with the same postId on Iphone and Android, so the output of the createPostLink method with postId ( example : 3cjsRsTIicIaVK2anA5x ) is :

Iphone : https://myappname.page.link/abcd Android : https://myappname.page.link/efgh

so I have try to debug those link by adding param d=1

for Iphone this is the debug output for URL https://myappname.page.link/abcd?d=1

The dynamic link has 2 warning(s)

    We could not find Android package name 'com.mydomain.myapp.xxxx' in this Google project. Learn more.
    There is no configuration to prevent phishing on this domain https://myappname.page.link. Setup URL patterns to whitelist in the Firebase Dynamic Links console. Learn more.
image

for Andoid this is the debug output for URL https://myappname.page.link/efgh?d=1

The dynamic link has 2 warning(s)

    We could not find bundle ID 'com.mydomain.myapp.xxxx' in this Google project. Learn more.
    There is no configuration to prevent phishing on this domain https://myappname.page.link. Setup URL patterns to whitelist in the Firebase Dynamic Links console. Learn more.
image

@darshankawar hope this can help you to find something :)

darshankawar commented 2 years ago

Thanks for the update. Keeping it open for further investigation from the team. /cc @russellwheatley

russellwheatley commented 2 years ago

Hey @azazadev, I've just tested creating a short dynamic link on iOS which opened my app. I then used the same link to open my android app and it worked. I used the example app code here.

I would advise building in release mode for it to work though (i.e. flutter run --release). Could you try and let me know if it works? Thanks

google-oss-bot commented 2 years ago

Hey @azazadev. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

azazadev commented 2 years ago

Hey @azazadev, I've just tested creating a short dynamic link on iOS which opened my app. I then used the same link to open my android app and it worked. I used the example app code here.

I would advise building in release mode for it to work though (i.e. flutter run --release). Could you try and let me know if it works? Thanks

Thanks @russellwheatley , i will try to test again when i have some time. Issue can be closed if no answer from my side

google-oss-bot commented 2 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@azazadev if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.