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

5.2k views Asked by At

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.

3

There are 3 answers

0
David Jones On BEST ANSWER

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.

0
João Paulo On

You can use react-native-rename to rename your application and define a Bundle Identifier:

npx react-native init AwesomeProject
cd AwesomeProject
npx react-native-rename "Awesome Project" -b br.com.joaops.AwesomeProject
1
Pavel Chuchuva On

Use --package-name parameter:

npx react-native@latest init GlowCalculator --package-name com.codebusterspro.glowcalculator --title "Glow Calculator"

See https://github.com/react-native-community/cli/issues/1111#issuecomment-1562278377