React-native-firebase: Dynamic Links - createShortDynamicLink not working on Android

Created on 3 Oct 2018  路  11Comments  路  Source: invertase/react-native-firebase

Issue

Reference:
https://rnfirebase.io/docs/v5.x.x/links/reference/links

I'm am trying to generate a short dynamic link see code below:

 firebase.links().createShortDynamicLink(dynamicLink, 'UNGUESSABLE')
     .then((url) => {
         console.log(url);
      })
      .catch((error) => {
          console.log(error);
      });

This is working fine on iOS but on Android I'm getting this error:

Error: 8:
at createErrorFromErrorData (NativeModules.js:146)
at NativeModules.js:95
at MessageQueue.__invokeCallback (MessageQueue.js:397)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at t (RNDebuggerWorker.js:1)

Relevant gradle dependencies:

implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-invites:16.0.3"

Funnily enough _createDynamicLink(dynamicLink)_ works fine on both platforms.

Environment

  1. Application Target Platform:

Android

  1. Development Operating System:

macOS Sierra

  1. Build Tools:

Android SDK version 27

  1. React Native version:

0.57.0

  1. React Native Firebase Version:

5.0.0

  1. Firebase Module:

Dynamic Links

  1. Are you using typescript?

no

Android Invites Links Firebase

Most helpful comment

Hi @jeremywen3 and @nabylb I found out the issue. The current version of firebase-dynamic -links is broken for generating short links. This is causing an error to throw that is unhandled by firebase and presents in a lot of weird ways. I found that be downgrading my firebase versions to 16.0.1 it fixed these issue. Here is my modified app/build.gradle:

    compile 'com.google.firebase:firebase-core:16.0.1'
    compile 'com.google.firebase:firebase-storage:16.0.1'
    compile 'com.google.firebase:firebase-auth:16.0.1'
    compile 'com.google.firebase:firebase-messaging:17.3.3'
    compile 'com.google.firebase:firebase-invites:16.0.1'
    compile 'com.google.firebase:firebase-dynamic-links:16.0.1'

All 11 comments

I have the exact same error.

implementation "com.google.firebase:firebase-core:16.0.4"
implementation "com.google.firebase:firebase-invites:16.0.4"
Error: 8: 
    at createErrorFromErrorData (NativeModules.js:146)
    at NativeModules.js:95
    at MessageQueue.__invokeCallback (MessageQueue.js:392)
    at MessageQueue.js:128
    at MessageQueue.__guard (MessageQueue.js:291)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:127)
    at t (RNDebuggerWorker.js:1)

I am having the same issue.

Hi @jeremywen3 and @nabylb I found out the issue. The current version of firebase-dynamic -links is broken for generating short links. This is causing an error to throw that is unhandled by firebase and presents in a lot of weird ways. I found that be downgrading my firebase versions to 16.0.1 it fixed these issue. Here is my modified app/build.gradle:

    compile 'com.google.firebase:firebase-core:16.0.1'
    compile 'com.google.firebase:firebase-storage:16.0.1'
    compile 'com.google.firebase:firebase-auth:16.0.1'
    compile 'com.google.firebase:firebase-messaging:17.3.3'
    compile 'com.google.firebase:firebase-invites:16.0.1'
    compile 'com.google.firebase:firebase-dynamic-links:16.0.1'

I am having the same issue.

I fixed this with a workaround
I used createDynamicLink instead of createShortDynamicLink and used this endpoint

POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={api_key}
Content-Type: application/json

{
   "longDynamicLink": "https://example.page.link/?link=http://www.example.com/&apn=com.example.android&ibi=com.example.ios",
   "suffix": {
     "option": "UNGUESSABLE"
   }
}

Or you can do it

POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={api_key}
Content-Type: application/json

{
  "dynamicLinkInfo": {
    "dynamicLinkDomain": "example.page.link",
    "link": "https://www.example.com/",
    "androidInfo": {
      "androidPackageName": "com.example.android"
    },
    "iosInfo": {
      "iosBundleId": "com.example.ios"
    }
  }
}

reference : google docs-dynamic-links-rest

The problem is the new Google Play services apk.
It works fine with previous version such as 13.2.80.

It appears that Firebase have fixed it. createShortDynamicLink is working on 16.0.3

The latest release requires 16.0.3+ and above so I'd consider this resolved now.

i am using the latest release

implementation "com.google.firebase:firebase-invites:16.0.4"
implementation "com.google.firebase:firebase-dynamic-links:16.1.2"

but still didn't work. Error still occured:

at createErrorFromErrorData (NativeModules.js:146)

I was having a hell of a time getting firebase updated without Android blowing up. After a couple of days of banging my head against the wall, I went with @jcsena's workaround. Here's some typescript code if you're having trouble too:

interface ShortLinksResponse {
  previewLink: string;
  shortLink: string;
  warning?: Array<{ warningCode: string; warningMessage: string }>;
}

// This is a workaround for a bug with shot links.  Upgrading android was causing gradle problems.
const convertDynamicLinkUrlToShortLink = async (url: string) => {
  try {
    const endpoint = `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${
      AppConfig.firebase.apiKey
    }`;
    const body = JSON.stringify({
      longDynamicLink: url,
      suffix: { option: 'SHORT' },
    });
    const init: RequestInit = {
      body,
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      method: 'POST',
    };
    const res = await fetch(endpoint, init);
    const links: ShortLinksResponse = await res.json();
    return links.shortLink;
  } catch (e) {
    throw e;
  }
};

upgrading to 16.0.6 fixes issue for me. Good luck!

Was this page helpful?
0 / 5 - 0 ratings