7

I've created an app in react-native. I need the package name to be: com.org.appname

React-native does not allow you to specify this as the package name in the init, or to change it after init.

react-native init --package="com.org.appname" 

does not work

Changing the package name as described in Change package name for Android in React Native also doesn't work and results in the following error on react-native run-android

Failed to finalize session : INSTALL_FAILED_VERSION_DOWNGRADE

5 Answers 5

19

in iOS project you just need to change BundleID with Xcode.

In Android project you need to change package name in 4 files:

android/app/src/main/java/com/reactNativeSampleApp/MainActivity.java android/app/src/main/java/com/reactNativeSampleApp/MainApplication.java android/app/src/main/AndroidManifest.xml android/app/build.gradle 

good practice is also to modify BUCK file in Android project, in two places, and correspondingly adjust hierarchy in android project, although it is not necessary:

BUCK file:

 android_build_config( name = "build_config", package = "app.new.name", ) android_resource( name = "res", package = "app.new.name", res = "src/main/res", ) 

run command ./gradlew clean

Sign up to request clarification or add additional context in comments.

1 Comment

Is there an update to this? Currently only changing the BundleID with Xcode did not work with RN 0.61.
8

According to this https://saumya.github.io/ray/articles/72/, you can run this command from the start

react-native init MyAwesomeProject -package "com.example.app" 

But if you already generated your app via

react-native init MyAwesomeProject 

You can modify app name in file

android/app/src/main/res/values/strings.xml 

Then you can modify package name in files

android/app/src/main/java/com/reactNativeSampleApp/MainActivity.java android/app/src/main/java/com/reactNativeSampleApp/MainApplication.java android/app/src/main/AndroidManifest.xml ( optional as per my experience ) android/app/build.gradle 

Lastly, run the following commands (from inside the app's android/ directory)

./gradlew clean ./gradlew assembleRelease 

To change iOS version package name, use Xcode

2 Comments

where is this stuff documented? even just the cli options? crazy that so much has been put into this project, yet nothing into detailed documentation!
the -package option is not supported, does not work and the article in the link is incorrect in other ways, suggest removing it.
1

I use the react-native-rename npm package.

Install using

npm install react-native-rename -g 

Then from the root of your React Native project execute the following

react-native-rename "MyApp" -b com.mycompany.myapp 

react-native-rename on npm

1 Comment

This did work with prior version in android, however using it with 0.71.2 wont work anymore. Already updated the package to it's new version.
0

If your text editor able to replace a string in all of your project files it is very easy to change package id.

I am using PhpStorm and I just replaced my old.package.id with new.package.id in all of my project files. It worked for me

Comments

0

simply just change your package name in these 4 files

android => app => src => main => java => com => reactNativeSampleApp => MainActivity.java & MainApplication.java android => app => src => main => AndroidManifest.xml android => app => build.gradle

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.