npmreact-nativereact-native-iosnpx

How to define own package name/bundle identifier when creating react native project


Could give me somebody advice how to define own package name/bundle identifier when I creating new application in react native?

I used command npx react-native MyApp --package=com.myCompany.myApp or npx react-native MyApp -package "com.myCompany.myApp" but everytime npx created project with package name com.myApp instead of com.myCompany.myApp. I don't want to change package name manualy or help by react-native-rename because I want to set name in time of creation. So it is somehow posible?

Thanks so much guys.


Solution

  • Unfortunately, no. The --package switch was removed some time ago. But it's a pretty easy fix, as long as you do it right after creating your project (before running it for the first time). You'll need to use an editor that has a project-wide find and replace (Atom, VS Code, Nova, etc.).

    First, initialize the project like so:

    npx react-native init AwesomeProject
    

    Then, do a project-wide find and replace:

    com.awesomeproject → com.mycompany.myapp
    

    As long as you do this before you run the app for the first time, there should only be a handful of replacements. If you want to be extra careful, you can make each change manually.

    Then, just modify the folder structure to reflect the new package name:

    src/main/java/com/awesomeproject → src/main/java/com/mycompany/myapp
    

    If you needed to automate this for some reason, you would need to write your own script to make the above changes.