react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

On android after installing app getInitialLink() is NULL

Open vvusts opened this issue 8 years ago • 12 comments

Issue

This issue is when app is not installed on device.

  • On IOS press on dynamic link it opens store I install app, press open and getInitialLink() is called url parameter is ok.

  • On Android press on dynamic link opens store I install app, press open and getInitialLink() is called but url parameter is NULL.

Environment

  1. Application Target Platform:

Android (5,6,7,8)

  1. React Native version:

0.52.1

  1. React Native Firebase Version:

4.2.0

  1. Firebase Module:

Dynamic Links

  1. Are you using typescript?

No


Loving react-native-firebase? Please consider supporting their open collective:

👉 https://opencollective.com/react-native-firebase/donate

vvusts avatar Jul 04 '18 12:07 vvusts

I have just debugged native code. And I am getting null for mInitialLink in: nodeModules....react-native-firebase/android/src/main/java/io/invertase/firebase/links/RNFirebaseLinks.java Code:

@ReactMethod
  public void getInitialLink(final Promise promise) {
    if (mInitialLinkInitialized) {
      promise.resolve(mInitialLink);
    } else {
      if (getCurrentActivity() != null) {
        FirebaseDynamicLinks.getInstance()
          .getDynamicLink(getCurrentActivity().getIntent())
          .addOnSuccessListener(new OnSuccessListener<PendingDynamicLinkData>() {
            @Override
            public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
              if (pendingDynamicLinkData != null
                && !isInvitation(pendingDynamicLinkData)) {

                mInitialLink = pendingDynamicLinkData.getLink().toString();
              }
              Log.d(TAG, "getInitialLink: link is: " + mInitialLink);
              mInitialLinkInitialized = true;
              promise.resolve(mInitialLink);

How I did it. I clicked on link on emulator. Then I run debug from android studio which installed app on emulator. Then this code was executed.

vvusts avatar Jul 04 '18 20:07 vvusts

Please check images. This is behaviour when debug. You can see that after app install I have link for pendingDynamicLinkData.getLink() but mInitialLink is without value somehow. screen shot 2018-07-06 at 13 40 09 2 screen shot 2018-07-06 at 13 40 21 2

vvusts avatar Jul 06 '18 11:07 vvusts

Even if I do this:

     //if (pendingDynamicLinkData != null
     // && !isInvitation(pendingDynamicLinkData)) {
     mInitialLink = pendingDynamicLinkData.getLink().toString();
     //}

in java code mInitialLink is always null.

vvusts avatar Jul 06 '18 12:07 vvusts

This is versions that I use:

implementation project(':react-native-firebase')
    implementation "com.google.firebase:firebase-messaging:15.0.2"
    implementation "com.google.firebase:firebase-invites:15.0.1"
    implementation "com.google.android.gms:play-services-base:15.0.0"
    implementation "com.google.firebase:firebase-core:15.0.2"

I don't know if there is something important that I can write.

vvusts avatar Jul 06 '18 12:07 vvusts

I created a new project with all latest libraries and again same problem. I posted project to: https://github.com/vvusts/firebaseDynamicLinksDemo Summary this is new project, only android configured.

I tried RN firebase version 4.1.0 and 4.2.0 I tried firebase from 15.0.2 to 11.4

vvusts avatar Jul 09 '18 11:07 vvusts

@vvusts let me know how you get on with your release build after tonights screenshare, should in theory be working now.

For others; we used the App Link Assistant (always ignore step 2 on it) in Android Studio to configure / verify the links are working; Tools -> App Link Assistant and then uploading the SHA256 from the generated DAL file to the firebase console app. Worth noting you can only have one of these working at a time, multiple SHA256's on the firebase console will default to the latest one only, bit annoying as you can't test debug and release together.

You can see which SHA256 is active by visiting https://YOUR_DOMAIN.page.link/.well-known/assetlinks.json

ALA: image


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Jul 09 '18 20:07 Salakar

Hi, thank you @Salakar for all help on this issue (app is on store and initial link work). The only thing that is required to be changed in module code is:

private boolean isInvitation(PendingDynamicLinkData pendingDynamicLinkData) {
    return false;  //return FirebaseAppInvite.getInvitation(pendingDynamicLinkData) != null;
  }

I will leave it like this for now if I uncomment it initial link again doesn't work (I returned all other changes).

SHA256: is also important to mention that when it's updated on the firebase console it can still show the previous one as Firebase cache it, so you may need to wait 5-10 minutes before it shows on the assetlinks.json url and works everywhere else.

@Salakar already wrote about other stuffs so I will not mention it. Once again thank you for help and support. We can close this one.

vvusts avatar Jul 10 '18 11:07 vvusts

@vvusts good to hear you've got your app released and working, that long screenshare session last night was worth it in the end then 😄

Might be worth us removing that isInvitation check, not entirely sure what it's achieving to be honest. Could leave the checking up to users in JS land as an invite is still a link technically... e.g. the following could be done in JS land:

const invitation = await firebase.invites().getInitialInvitation();
const link = await firebase.links().getInitialLink();

if (link && !invitation) {
 // or something
}

Will close and add a note in our internal issue tracker to revisit the isInvitation issue.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Jul 10 '18 14:07 Salakar

@Salakar Any timeline for isInvitation fix on android? I can confirm the solution suggested by @vvusts fixes the issue. Adding an additional check for getInvitationId if its empty works for me:

  private boolean isInvitation(PendingDynamicLinkData pendingDynamicLinkData) {
        FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(pendingDynamicLinkData);
        if (invite != null && invite.getInvitationId() != null && !invite.getInvitationId().isEmpty()) {
           return true;
        }
        return false;
   }

If this looks ok I can submit PR.

bilalsyed001 avatar Jul 11 '18 10:07 bilalsyed001

@bilalsyed001 yes please, the above as a PR would be great, I can merge and then do a patch release later today

Salakar avatar Jul 11 '18 12:07 Salakar

#1293

bilalsyed001 avatar Jul 11 '18 12:07 bilalsyed001

@bilalsyed001 v4.3.5 published with your PR included, let me know if there's any further issues.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Jul 11 '18 13:07 Salakar