Harry Moreno
Harry Moreno

Reputation: 11613

How to change React Native Android project name

I need to change the name of my React Native Android project. I changed my app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.[new name here]">

but when I try to build a release apk I get the following error

:app:compileReleaseJavaWithJavac
/Users/harrymoreno/programming/contactsPro/android/app/src/main/java/com/contactspro/MainActivity.java:34: error: cannot find symbol
            .setUseDeveloperSupport(BuildConfig.DEBUG)
                                    ^
  symbol:   variable BuildConfig
  location: class MainActivity
1 error
:app:compileReleaseJavaWithJavac FAILED

Upvotes: 4

Views: 4213

Answers (2)

Harry Moreno
Harry Moreno

Reputation: 11613

I solved this by searching through the entire project for instances of the old project name using ripgrep and replacing the string in some places (don't try the files listing strings). At least 4 files need to be edited in order to change app name.

  • android/app/src/main/AndroidManifest.xml
  • android/app/src/main/PATH/TO/JAVA/FILES/MainActivity.java
  • android/app/src/main/PATH/TO/JAVA/FILES/MainApplication.java
  • /android/app/build.gradle

for example in /android/app/build.gradle

android {
 buildToolsVersion "23.0.1"

 defaultConfig {
     applicationId "com.[change name]"
     minSdkVersion 16
     targetSdkVersion 22
     versionCode 2

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.[change name]">

/android/app/src/main/java/com/contactspro/MainActivity.java

package com.[change name];

Upvotes: 15

Adriano Tadao
Adriano Tadao

Reputation: 986

The main problem here was that when you rename the project through react-native command, it create a new folder with the new project name and it raises an error because you have two main files.

I removed the older folder with the old project files and then, everything works fine.

Upvotes: 0

Related Questions