我使用React - Native init MyApp初始化一个新的React Native应用程序。 这创建了一个带有com.myapp包的Android项目。

更改这个包名称的最佳方法是什么,例如:com.mycompany.myapp?

我尝试在AndroidManifest.xml中更改它,但它创建了其他错误,所以我假设这不是方法。

任何想法?


当前回答

进入文件android/app/src/main/AndroidManifest.xml -

更新:

attr android:元素应用程序的标签为:

旧值- android:label="@字符串/app_name" android:label="(你想放的字符串)"

and

attr android:标签的元素活动为:

旧值- android:label="@字符串/app_name" android:label="(你想放的字符串)"

为我工作过,希望能有所帮助。

其他回答

这些信息对你很有帮助,所以仔细听……

After updating package name and changing files, don't forget to change in 
package.json and app.json file at the root directory of your react native project

否则,您将得到下面的错误

Invariant Violation: "Your new package name" has not been registered

在VS Code中,按Ctrl + Shift + F,在“Find”中输入旧的包名,在“Replace”中输入新包名。然后按“替换所有事件”。

绝对不是务实的方式。但是,这对我来说很管用。

如果您正在使用Android Studio-

com的变化。Myapp到com.mycompany.myapp

create a new package hierarchy com.mycompany.myapp under android/app/src/main/java Copy all classes from com.myapp to com.mycompany.myapp using Android studio GUI 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. Update android/app/src/main/AndroidManifest.xml and android/app/build.gradle (replace com.myapp to com.mycompany.myapp Sync the project (gradle build)

2021年没有世博会

设原App名称为:com.myApp 让新的应用程序名称:com.newname.myApp

android\app\src\main\AndroidManifest.xml


重命名xml属性:' package="com.newname.myApp"


android主要\ app \ src \ \ java \ com \ [yourAppName] \ MainActivity.java

重命名包com.myApp的第一行;来打包com.newname.myApp;


android主要\ app \ src \ \ java \ com \ [yourAppName] \ MainApplication.java

重命名第一行到包com.newname.myApp;

在类中私有静态void initializeFlipper 复述这句话:

Class<?> aClass = Class.forName(“com.myApp.ReactNativeFlipper”);

To

Class<?> aClass = Class.forName(“com.newname.myApp.ReactNativeFlipper”);


Android\app\build.gradle

在defaultConfig上重命名applicationId

“com.newname.myApp”


在命令行上运行: $ NPX react-native start $ NPX react-native run-android

重命名所有包名后, 来自android studio。File ->使缓存失效/重新启动可以修复这类错误

这对我很有效