2

at the moment I am facing a problem which I try to solve since 3 days already.. I want to rename my package name for my react native android application.

So, to be completely sure I am doing everything correct I have created a new project and tried to rename the package name. I have done this to be sure the error is not coming from my project and I haven't been able to fix my error yet.

I have initialized a new project like always: react-native init MyAwesomeProject .

Then I have replaced com.myawesomeproject in the following files with com.awesome.project.

/android/app/BUCK:

android_build_config(
...
package = 'com.awesome.project',
)
android_resource(
...
package = 'com.awesome.project',
)

android/app/src/main/AndroidManifest.xml

package="com.awesome.project"

android/app/build.gradle

defaultConfig {
    applicationId "com.awesome.project"
    ...
}

Also I have replaced package com.myawesomeproject; with package com.awesome.project; and moved the MainActivity.java and MainApplication.java file from android/app/src/main/java/com/myawesomeproject/to the new path android/app/src/main/java/com/awesome/myawesomeproject/.

After I have done all those changes I runned ./gradlew clean inside my android folder followed by this command react-native run-android.

However, I am still facing exact the same problem I am facing in my actual project.

> Task :app:compileDebugJavaWithJavac FAILED
/Users/max/Desktop/Max/MyAwesomeProject/android/app/src/main/java/com/myawesomeproject/MainApplication.java:19: error: cannot find symbol
      return BuildConfig.DEBUG;
             ^
  symbol: variable BuildConfig
1 error


FAILURE: Build failed with an exception. 

Also, I have already tried to add the following code to the top of the MainApplication.java file:

import com.facebook.react.BuildConfig;

But I have added the code to the MainApplication.java located in android/app/src/main/java/com/myawesomeproject like it is saying it in the error output. If you do that, the console is not throwing any error after running react-native run-android, however, the App myawesomeproject gets installed and if you try to open it, the app crashes.

This clearly shows that react is still using the wrong path!

I even have tried the npm rename package and runned the following command:

react-native-rename "project" -b com.project.

Not even this is solving my problem. I still get exactly the same error when running react-native run-android.

You guys can see the problem is not coming from my project cause I have exactly the same problem after I have set up a new project which is completely build from the scratch!

I would appreciate any kind of help! Thank You guys.

Jan
  • 1,180
  • 3
  • 23
  • 60

1 Answers1

9

There are changes to be made in multiple files when re-naming. So it can get tricky. Using react-native rename makes it very easy.

Using react-native-rename

I just tried setting up an initial project using: react-native init MyAwesomeProject

Then I ran: npm install react-native-rename -g

Then to change the name of the project I ran cd MyAwesomeProject followed by

react-native-rename "project" -b com.awesome.project

Then running react-native run-android it builds without errors.

Android Manually

If you plan to do the changes manually then there are a lot of files to change. There may actually be more depending on what you have added to your project. This is a guide for changing a vanilla project.

In the application root

In the app.json change the name and the displayName to be "project"

In the package.json change the name to be "name": "project",

android/settings.gradle

Change the rootProject.name to the name that you want: rootProject.name = 'project'

android/app/build.gradle

In the default config change the applicationId to the application Id that you want, in this case: applicationId com.awesome.project

android/app/BUCK

Change the package in both the android_build_config and the android_resources to the desired package, in this case: package = "com.awesome.project",

android/app/src/main/AndroidManifest.xml

Change the package to the desired package name, in this case: package="com.awesome.project"

android/app/src/main/res/values/strings.xml

Change the app name to the desired app name, in this case <string name="app_name">project</string>

Updating the *.java files

This bit is tricker as you have to create folders, move files and then rename parts of the internals of the files.

android/app/src/main/java/com/

Create a folder called awesome and inside that folder create a folder called project

Copy the MainActivty.java and the MainApplication.java from the android/app/src/main/java/com/myawesomeproject into the recently created android/app/src/main/java/com/awesome/project folder.

Inside the both the MainActivity.java and the MainApplication.java remane the package at the top of the files from package com.myawesomeproject; to package com.awesome.project;

Also in the MainActivity.java rename the string that is returned by the getComponentName() function to "project"

Manually iOS

It is a little tricker to do manually however it is simple to change the bundle id and the app name inside Xcode. I'm not about to go through the Xcode procedure as you have just asked specifically for Android.

Andrew
  • 26,706
  • 9
  • 85
  • 101
  • using `react-native-rename` it's very messed, changed manually worked very well "android right now", Anyway Thank you you save my day ;) – Oliver D Oct 12 '20 at 16:56