Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change package name for Android in React Native

People also ask

How do I rename a package in react native?

Steps: Firstly close all editors/studio eg: xcode android studio vscode and then Install package "react-native-rename" in the terminal by running the command (Keep your project folder copy in another folder for backup if you don't feel this safe):

Can I change package name Android?

Step 1: To rename package name in Android studio open your project in Android mode first as shown in the below image. Step 2: Now click on the setting gear icon and deselect Compact Middle Packages. Step 3: Now the packages folder is broken into parts as shown in the below image.


I've renamed the project' subfolder from: "android/app/src/main/java/MY/APP/OLD_ID/" to: "android/app/src/main/java/MY/APP/NEW_ID/"

Then manually switched the old and new package ids:

In: android/app/src/main/java/MY/APP/NEW_ID/MainActivity.java:

package MY.APP.NEW_ID;

In android/app/src/main/java/MY/APP/NEW_ID/MainApplication.java:

package MY.APP.NEW_ID;

In android/app/src/main/AndroidManifest.xml:

package="MY.APP.NEW_ID"

And in android/app/build.gradle:

applicationId "MY.APP.NEW_ID"

In android/app/BUCK:

android_build_config(
  package="MY.APP.NEW_ID"
)
android_resource(
  package="MY.APP.NEW_ID"
)

Gradle' cleaning in the end (in /android folder):

./gradlew clean

I use the react-native-rename* npm package. Install it via

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

To change the package name from com.myapp to: com.mycompany.myapp (for example),

  1. For iOS app of the react app, use xcode - under general.
  2. For the android app, open the build.gradle at module level. The one in the android/app folder. You will find
// ...
defaultConfig {
     applicationId com.myapp
     // ...
}
// ...

Change the com.myapp to whatever you need.

Hope this helps.


you can simply use 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

but notice that, this lib remove your MainActivity.java and MainApplication.java. before changing your package name, give a backup from this two file and, after changing package name just put it back to their place. this solution work for me

more info: react-native-rename