Issues with Linking: Deep links opening in dev mode but not in Android published builts (standalone app)

#1

Hi all!

We’re facing a similar issue than the one in this topic Linking.addEventListener(‘url’) working on iOS but not on Android in production.

Everything goes fine and smooth in dev, but when we try to open a link with Linking.openUrl(url) with a published built, it gives us the error "Could not load myapp://path."
In the error log it says “Uncaught Error: java.net.UnknownHostException: Unable to resolve host “path”: No address associated with hostname” (and so Linking.addEventListener(‘url’) is never triggered).

Linking.getInitialURL() is working just fine.

Our app.json includes in expo the “scheme”: “myapp”.
We have a handmade url received in the app which we want to direct us to some other place inside the app with some specific params included, a little summary would be something like this:

async openUrl(url) {
    try {
      const can = await Linking.canOpenURL(url);
      if (can) {
        Linking.openURL(url);
        return;
      } else {
        Analytics.exception(new Error(`Can't open' url ${url}.`));
      }
    }
    catch (e) {
      Analytics.exception(e);
    }
    Alert.alert(I18n.t('unknown_error'));
}
render() {
    const n = this.state.preparedData;
    let url = '';
    let label = n.label;
    let button = null;
    if (n.url) {
        url = n.url;
        label = label || I18n.t('open');
    }
    if (url.startsWith('myapp://')) {//Change myapp urls to make it work on expo client
        url = url.replace('myapp://', Expo.Linking.makeUrl('/'));
     }
    if (url && label) {
        button = (
            <Button
             onPress={() => this.openUrl(url)}
             title={label}/>
         );
     }
    return (
        <Card title={n.subject}>
          {button}
        </Card>
    );
}

We’ve tried adding some more info after assigning the url to see if it was a definition problem, but it seems to be parsing the url just fine.

const { path, queryParams } = Expo.Linking.parse(url);
alert(`${url}: \nLinked to app with path: ${path} and data: ${JSON.stringify(queryParams)}`);

We’re currently testing in a Samsung Galaxy J7, Android 7.1.1, but it has also failed in all other Android devices that we’ve tried.

Note:
If we overwrite the url, and instead of sending the path and its params we do

url = Expo.Linking.makeUrl('/');

the app opens with no further problems.


Sorry for the long post, I wanted to make it as clear as possible.

We’ve tried with expo 30.0, 29.0 and 27.0 and it’s not working on any of them.
It works perfectly on iOS though, so maybe there’s something from Android that we’re missing?

Could somebody help us find what we’re doing wrong?
Thank you.

0 Likes

Linking.addEventListener('url') working on iOS but not on Android in production
#2

I’ve made a quick clean app with create-react-native-app my-project to test this functionality, added "scheme": "myproject" to the app.json and created a button that tries to open Expo.Linking.makeUrl('notas/'); which returns the same error than the one I mentioned before.

0 Likes

closed #3

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

0 Likes