react-native-map-link icon indicating copy to clipboard operation
react-native-map-link copied to clipboard

Update document of Post-install steps for expo user

Open qaws5503 opened this issue 3 years ago • 6 comments

I dig in with the problem here #209 . After plenty of hours, I finally work through it. As the author mention in Post-install steps Android must update AndroidManifest.xml. But in the Expo section it only says how it works on iOS, doesn't mention how to work on android while using Expo.

So I searched how to change AndroidManifest.xml file in Expo. And the answer is using plugins, but this only work on Expo SDK 41 or greater, please check for the SDK first.

So follow the steps below:

  1. create a file called withAndroidPackageVisibile.js, and paste this to the file. This will write the same AndroidManifest.xml mention in Post-install steps Android steps.
const { withAndroidManifest } = require("@expo/config-plugins");

module.exports = function androidManifestPlugin(config) {
  return withAndroidManifest(config, async (config) => {
    let androidManifest = config.modResults.manifest;
    androidManifest["queries"] = [
      ...androidManifest["queries"],
      packageVisibilityList,
    ];
    return config;
  });
};
const packageVisibilityList = {
  intent: [
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "geo",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "google.navigation",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "applemaps",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "citymapper",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "uber",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "lyft",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "transit",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "truckmap",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "waze",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "yandexnavi",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "moovit",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "yandexmaps://maps.yandex.",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "yandextaxi",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "kakaomap",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "mapycz",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "mapsme",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "osmand.geo",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "gett",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "nmap",
        },
      },
    },
    {
      action: {
        $: {
          "android:name": "android.intent.action.VIEW",
        },
      },
      data: {
        $: {
          "android:scheme": "dgis",
        },
      },
    },
  ],
};

  1. Then switch to app.json and change the following
{
  "expo": {
      ...
    "plugins": [
        ... ,
        "./the/path/to/withAndroidPackageVisibile.js"
      ]
  }
}
  1. Finally re-build the app, I only test on eas build. I can't assure there is no problem with expo build.

You can learn more about how to use plugins in here. Happy coding guys!

qaws5503 avatar Feb 23 '22 07:02 qaws5503

Hi, It still won't open for me. Are there any permission that need to be added?

emehmet avatar Apr 01 '22 15:04 emehmet

Hi, It still won't open for me. Are there any permission that need to be added?

@emehmet I didn't add any extra permission, so I recommend you to check if AndroidManifest.xml has correctly been changed. You can check it by below.

You can first type expo eject in the command line. Then find AndroidManifest.xml under android folder and check for if the permission is like this. By doing this you can check if withAndroidPackageVisibile.js works like what you want.

qaws5503 avatar Apr 12 '22 16:04 qaws5503

I dig in with the problem here #209 . After plenty of hours, I finally work through it. As the author mention in Post-install steps Android must update AndroidManifest.xml. But in the Expo section it only says how it works on iOS, doesn't mention how to work on android while using Expo.

So I searched how to change AndroidManifest.xml file in Expo. And the answer is using plugins, but this only work on Expo SDK 41 or greater, please check for the SDK first.

So follow the steps below:

  1. create a file called withAndroidPackageVisibile.js, and paste this to the file. This will write the same AndroidManifest.xml mention in Post-install steps Android steps.
const { withAndroidManifest } = require("@expo/config-plugins");

module.exports = function androidManifestPlugin(config) {
  return withAndroidManifest(config, async (config) => {
    let androidManifest = config.modResults.manifest;
    androidManifest["queries"] = [
      ...androidManifest["queries"],
      packageVisibilityList,
    ];
    return config;
  });
};

thanks for your solution but it seems should modify it a little bit here.

module.exports = function androidManifestPlugin(config) {
   return withAndroidManifest(config, async (config) => {
     let androidManifest = config.modResults.manifest;
     androidManifest["queries"] = [
       ...androidManifest["queries"],
       packageVisibilityList,
     ];

     config.modResults.manifest = androidManifest; // here

     return config;
   });
 };

chunhungchen avatar Apr 22 '22 19:04 chunhungchen

Hi, I tried this solution but it only works for me in Expo Go or with expo eject/'expo prebuild'. While using expo build:android the apk does not contain output of your plugin. I decompiled the apk using apktool and the AndroidManifest does not contain those intents. Did you managed to make it work with expo managed project on standalone build?

I'm using Expo SDK 43 and version "2.9.3" of this library

Buk1m avatar May 16 '22 16:05 Buk1m

It worked for me when I deleted node_modules and build again with eas build on development-client.

emehmet avatar May 17 '22 10:05 emehmet

Thanks, I will have to migrate the project to EAS cli, I will post an update if it is working on EAS build. (it may take few days as it's not a priority for now).

Buk1m avatar May 17 '22 10:05 Buk1m