Changing the package name in a react-native app
Solution 1
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
Solution 2
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
Dylan Spencer James
I am a Drupal developer, author of Drupal 7 Cookbook, and themer located in Swansea, Wales. I specialise in Open source CMSs. I've recently moved from Joomla to Drupal as my CMS of choice for new websites. Previously I have worked as a Flash/Actionscript developer specialising in large LMS implementations for clients such as the BBC, LearnDirect and Cambridge University Press. Other interests include, but are not limited to, skiing, cooking cycling and playing the piano.
Updated on June 11, 2022Comments
-
Dylan Spencer James almost 2 years
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
-
Wils over 4 yearsIs there an update to this? Currently only changing the BundleID with Xcode did not work with RN 0.61.