Change package name for Android in React Native

后端 未结 20 1797
鱼传尺愫
鱼传尺愫 2020-11-30 16:13

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.

相关标签:
20条回答
  • 2020-11-30 16:39

    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
    
    0 讨论(0)
  • 2020-11-30 16:39

    If you are using Android Studio-

    changing 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 Android studio GUI

    3. 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.

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

    5. Sync the project (gradle build)

    0 讨论(0)
  • 2020-11-30 16:42

    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 :)

    0 讨论(0)
  • 2020-11-30 16:42

    Simply using the search and replace tool of my IDE did the trick.

    0 讨论(0)
  • 2020-11-30 16:46

    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

    0 讨论(0)
  • 2020-11-30 16:46

    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.

    1. type "cd android"

    2. type "./gradlew clean"

    0 讨论(0)
提交回复
热议问题