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

Dynamic Links - createShortDynamicLink not working on Android

Open jeremywen3 opened this issue 8 years ago • 11 comments

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

jeremywen3 avatar Oct 03 '18 00:10 jeremywen3

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)

nabylb avatar Oct 04 '18 03:10 nabylb

I am having the same issue.

mfharding1 avatar Oct 05 '18 00:10 mfharding1

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'

mfharding1 avatar Oct 05 '18 16:10 mfharding1

I am having the same issue.

jcsena avatar Oct 05 '18 22:10 jcsena

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

jcsena avatar Oct 06 '18 03:10 jcsena

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

jjchula avatar Oct 07 '18 18:10 jjchula

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

jeremywen3 avatar Oct 08 '18 00:10 jeremywen3

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

Salakar avatar Oct 24 '18 14:10 Salakar

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)

ggdegreat avatar Nov 08 '18 03:11 ggdegreat

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;
  }
};

demoran23 avatar Dec 26 '18 14:12 demoran23

upgrading to 16.0.6 fixes issue for me. Good luck!

bilalsyed001 avatar Jan 02 '19 19:01 bilalsyed001