Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename appliaction package name - Not able to compile #22967

Closed
FrazeColder opened this issue Jan 11, 2019 · 2 comments
Closed

Rename appliaction package name - Not able to compile #22967

FrazeColder opened this issue Jan 11, 2019 · 2 comments
Labels
Bug DX Issues concerning how the developer experience can be improved. Resolution: Locked This issue was locked by the bot.

Comments

@FrazeColder
Copy link

Environment

React Native Environment Info:
System:
OS: macOS 10.14.1
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Memory: 32.00 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.13.0 - /usr/local/bin/node
Yarn: 1.12.1 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 23, 25, 27
Build Tools: 26.0.3, 27.0.3, 28.0.2, 28.0.3
System Images: android-27 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.57.8 => 0.57.8
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
react-native-rename: 2.4.0

Description

The problem I am facing is to rename the react native android application name. I have tried to solve this problem multiple times with different solutions, however, I am still not able to solve this problem. So, I decided to rebuild my problem in a new project to see if I still get the same error and the result is I get exactly the same error.

I even tried to use the [npm rename package][1] to set the package name by the plugin however, even this is producing exactly the same error!

Reproducible Demo

  1. Create a new project: react-native init MyAwesomeProject.
  2. Rename the package name by replacing com.myawesomeproject with com.awesome.project in the following files:

/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"
    ...
}
  1. Replace 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/.

  2. Run cd android && ./gradlew clean && cd ..

  3. Run the android application react-native run-android

  4. This should be the output (I get the exact same error 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. 

You can see, React tried to compile the wrong files. It is accessing the old path:
android/app/src/main/java/com/myawesomeproject/...

instead of the new (package name) one we set:
android/app/src/main/java/com/awesome/project/...

Comment

I have to add that somehow I have achieved to rename the android application name and it got installed on my android emulator. But the app didn't open up. I always got " has stopped". I got this error also with the new and clean initialized react native project. Sadly I cannot remember how to reproduce this error after all the different solutions I tried out..

@FrazeColder
Copy link
Author

FrazeColder commented Jan 11, 2019

I found the error

Finallllyyy..., after 3 days I found my error. Maybe you guys should add this to your doc. The name of the application, e.g. HelloWorld, has ALWAYS to match the name of the package ending!

So, if the name of the app is HelloWorld, the package has to be my.package.helloworld and inside the helloworld folder there need to be the MainActivity.java and MainApplication.java files!

@hramos hramos added the DX Issues concerning how the developer experience can be improved. label Jan 23, 2019
@hramos hramos removed the Bug Report label Feb 6, 2019
@elicwhite
Copy link
Member

Thanks for figuring this out and looking into it! Since you've already done the work, would you be willing to write a PR against the docs? https://github.com/facebook/react-native-website. A docs PR would be greatly appreciated to help people who run into this in the future!

Since this isn't an issue with React Native, I'm going to close this issue.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug DX Issues concerning how the developer experience can be improved. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants