I used react-native init MyApp
to initialise a new React Native app.
This created among others an Android project with the package com.myapp
.
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
If you are using Android Studio-
changing com.myapp
to com.mycompany.myapp
create a new package hierarchy com.mycompany.myapp under android/app/src/main/java
Copy all classes from com.myapp
to com.mycompany.myapp
using Android studio GUI
Android studio will take care of putting suitable package name for all copied classes. This is useful if you have some custom modules and don't want to manually replace in all the .java files.
Update android/app/src/main/AndroidManifest.xml
and android/app/build.gradle
(replace com.myapp
to com.mycompany.myapp
Sync the project (gradle build)
Go to Android Studio, open app, right click on java and choose New and then Package.
Give the name you want (e.g. com.something).
Move the files from the other package (you want to rename) to the new Package. Delete the old package.
Go to your project in your editor and use the shortcut for searching in all the files (on mac is shift cmd F). Type in the name of your old package. Change all the references to the new package name.
Go to Android Studio, Build, Clean Project, Rebuild Project.
Done!
Happy coding :)
Simply using the search and replace tool of my IDE did the trick.
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
If you are using VSCode
and Windows
.
1.Press Control + Shift + F
.
2.Find Your Package Name
and Replace All
with your new Package Name
.
type "cd android"
type "./gradlew clean"