react-native-rename icon indicating copy to clipboard operation
react-native-rename copied to clipboard

MainActivity.java problem

Open iAyubAnsari opened this issue 4 years ago • 12 comments

whenever I run this command npx react-native-rename 'appName' -b 'packageName'

this command deletes files MainActivity.java and MainApplication.java from this path 'android\app\src\main\java\com' please fixed this soon thank you

iAyubAnsari avatar Jan 19 '21 07:01 iAyubAnsari

@iAyubAnsari Make sure that you use the latest version v2.7

vomchik avatar Jan 19 '21 10:01 vomchik

I always use latest version .

iAyubAnsari avatar Jan 19 '21 10:01 iAyubAnsari

Could you provide more details about your project? the old and new bundle id. I have tested locally and all works fine with source code which was generated by react-native init

vomchik avatar Jan 19 '21 10:01 vomchik

I have faced same issue my old bundle id is com.app and i am renaming to com.app.appname then it deletes MainApplication.java and MainActivity.java both and new one is also not created.

I used command with npx so it must be latest as i am not installing it as global package and using npx instead.

hardikjs avatar Jan 25 '21 17:01 hardikjs

I also faced this bug. I noticed this happens when there is <space> in your name. To fix this I did the following steps :

  • Get the package name from AndroidManifest.xml from the manifest tag. For my case the new name was com.annotationapp
  • Create a new MainActivity.java file by copying from the previous one and change the name in two places.
-  package com.awesomeapp   // Remove this
+ package com.annotationapp  // Add this
...
protected String getMainComponentName() {
-    return "Awesome App";    // Remove this
+   return "Annotation App";  // Add this 
  }

Also search if any another place your name is there, change there also

  • Similarly go create aMainApplication.java by copying the previous one and change it:
-  package com.awesomeapp   // Remove this
+ package com.annotationapp  // Add this

...

 private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
-       Class<?> aClass = Class.forName("com.awesomeapp.ReactNativeFlipper")   // Remove this
+       Class<?> aClass = Class.forName("com.annotationapp.ReactNativeFlipper");  //Add this
        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
...

Search if any another place name is there, change it.

Then do a clean rebuild by cd android && gradlew clean && cd .. and then do start the server by resetting cache npm run android --reset-cache

uragirii avatar Jan 28 '21 09:01 uragirii

Is there any fix for this? The bug still occurs even if there is no space-character in the name.

All files from android\app\src\main\java\com\oldappname get deleted but the empty android\app\src\main\java\com directory is left. It also creates the new path android\app\src\main\java\com\myapp\appname but it's completely empty.

I'm using the latest version.

manuelbeier avatar Mar 25 '21 03:03 manuelbeier

+1, same issue

rejhgadellaabsl avatar Mar 31 '21 09:03 rejhgadellaabsl

+1 same issue

coolboy195 avatar Apr 07 '21 20:04 coolboy195

Please try the latest version v2.7.1 and let me know if it works for you

vomchik avatar Apr 09 '21 18:04 vomchik

Please try the latest version v2.7.1 and let me know if it works for you

Didn't work =(

duduccosta avatar Apr 22 '21 23:04 duduccosta

Please try a new version with a potential fix.

vomchik avatar May 31 '21 19:05 vomchik

I was having a similar issue where after renamed the project, the folder that contains MainApplication.java doesn't got renamed correctly. It's keeping with the same old previous name.

jpolvora avatar Apr 07 '22 01:04 jpolvora

Closing, check v3 now.

junedomingo avatar Dec 26 '22 09:12 junedomingo