Android package name change in React Native

I used react-native init MyApp to initialize a new React Native application. This created, among others, an Android project with the com.myapp package.

What is the best way to change the name of this package, for example: com.mycompany.myapp ?

I tried to change it in AndroidManifest.xml , but it created other errors, so I assume this is not the case.

Any idea?

+111
android react-native react-native-android
May 23 '16 at 11:34
source share
11 answers

I changed the name of 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 switch the old and new package identifiers:

In: Android / application /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" 

(Optional) On Android / App / BUCK:

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

Clearing Gradle 'at the end (in the / android folder):

 ./gradlew clean 
+253
May 23 '16 at 11:40
source share

I am using the response-native-rename npm package.

Install with

 npm install react-native-rename -g 

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

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

response-native-rename on npm

+59
Sep 17 '17 at 10:28
source share

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

  1. For an iOS app from a responsive app, use xcode - under the generic.
  2. For an Android application, open build.gradle at the module level. The one in the Android / application folder. You will find

    ... defaultConfig { applicationId com.myapp... }...

Change "com.myapp" to everything you need.

Hope this helps.

+8
Jul 02 '18 at 10:17
source share

You can simply use the response-native-rename npm package.

Install with

npm install react-native-rename -g

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

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

react-native-rename on npm

but note that this MainActivity.java removes your MainActivity.java and MainApplication.java . Before changing the name of your package, make a backup of these two files and, after changing the name of the package, simply return it to its place. this solution works for me

more information: Reaction-native-rename

+6
Jan 30 '19 at 8:55
source share

Goto android studio

Right-click on your package (most likely com) -> Refractor -> Rename -> Enter a name for the new package in the dialog -> Do Refractor

It will rename the name of your package everywhere.

+5
Mar 27 '18 at 12:52
source share

The initialization script generates a unique identifier for Android based on the name you gave it (for example, com.acmeapp for AcmeApp ).

To find out what name was generated, android/app/build.gradle applicationId key in android/app/build.gradle .

If you need to change this unique identifier, do it now, as described below:

In the /android folder, replace all occurrences of com.acmeapp with com.acme.app

Then change the directory structure using the following commands:

mkdir android/app/src/main/java/com/acme

mv android/app/src/main/java/com/acmeapp android/app/src/main/java/com/acme/app

You need a folder level for each point in the application identifier.

Source: https://blog.elao.com/en/dev/from-react-native-init-to-app-stores-real-quick/

+5
Aug 18 '18 at 17:18
source share

If you are using Android Studio-

change com.myapp to com.mycompany.myapp

  1. create a new package hierarchy com.mycompany.myapp under android/app/src/main/java

  2. Copy all classes from com.myapp to com.mycompany.myapp using the android studio GUI

  3. Android Studio will make sure that the name of the appropriate package is indicated for all copied classes. This is useful if you have several custom modules and you do not want to manually replace all .java files.

  4. Update android/app/src/main/AndroidManifest.xml and android/app/build.gradle (replace com.myapp with com.mycompany.myapp

  5. Synchronize Project (Gradle Build)

+4
Jan 15 '18 at 6:28
source share

I have a solution based on @Cherniv answer (works on macOS for me). Two differences: I have a Main2Activity.java file in the java folder with which I am doing the same, and I am not worried about the call. / gradlew clean, as it seems that this responder package does this automatically anyway.

In any case, my solution does what Cherniv does, except that I created a bash script shell for it, since I create several applications with one set of code and want to be able to easily change the package name whenever I run my npm scripts.

Here is the bash script I used. You will need to change the name of the package you want to use and add everything you want, but here is the basic information. You can create a .sh file, give permission, and then run it from the same folder in which you run response-native from:

 rm -rf ./android/app/src/main/java mkdir -p ./android/app/src/main/java/com/MyWebsite/MyAppName packageName="com.MyWebsite.MyAppName" sed -i '' -e "s/.*package.*/package "$packageName";/" ./android/app/src/main/javaFiles/Main2Activity.java sed -i '' -e "s/.*package.*/package "$packageName";/" ./android/app/src/main/javaFiles/MainActivity.java sed -i '' -e "s/.*package.*/package "$packageName";/" ./android/app/src/main/javaFiles/MainApplication.java sed -i '' -e "s/.*package=\".*/ package=\""$packageName"\"/" ./android/app/src/main/AndroidManifest.xml sed -i '' -e "s/.*package = '.*/ package = '"$packageName"',/" ./android/app/BUCK sed -i '' -e "s/.*applicationId.*/ applicationId \""$packageName"\"/" ./android/app/build.gradle cp -R ./android/app/src/main/javaFiles/ ./android/app/src/main/java/com/MyWebsite/MyAppName 

DISCLAIMER: First you need to first edit the MainApplication.java comment at the bottom of the java file. The comment has the word "package." Due to how the script works, it takes any line with the word "package" in it and replaces it. Because of this, this script cannot be verified by the future, as it may be the same word that is used elsewhere.

Second Disclaimer: The first 3 sed commands edit java files from the javaFiles directory. I created this directory myself, since I want to have one set of java files that were copied from there (since I could add new packages to it in the future). You might want to do the same. So copy all the files from the java folder (go to its subfolders to find the actual java files) and place them in a new folder called javaFiles.

Third failure: you will need to modify the packageName variable to match the paths at the top of the script and at the bottom (com.MyWebsite.MyAppName for com / MyWebsite / MyAppName)

+3
Jun 03 '17 at 18:59
source share

Follow the simple steps to rename the app name your app name Package name if you have not made any user changes in the Android folder (i.e. the script in which you just initialized the project)

  1. Just change the name in the package.json file and save it.
  2. Delete folder named Android
  3. Run the command " react-native upgrade

Note. As stated in the comment in ivoteje50 , do not delete the android folder if you have already followed the official instructions for creating the keystore, as it will delete the keystore and you will not be able to sign the new application again.

+2
Sep 07 '18 at 11:53 on
source share

In VS Code, press Ctrl + Shift + F enter the name of the old package in "Find" and enter the new package in "Replace". Then click Replace All Occurrences.

Definitely not a pragmatic way. But it helped me.

0
May 24 '19 at 12:09
source share

Go to file android / app / src / main / AndroidManifest.xml -

Update:

attr android: label application :

The old value is android: label = "@ string / app_name"

The new value is android: label = "(the string you want to put)

and

attr android: label element activity as:

The old value is android: label = "@ string / app_name"

The new value is android: label = "(the string you want to put)

Worked for me, hope this helps.

-5
May 23 '16 at 1:05
source share



All Articles