在React Native中更改Android的软件包名称 [英] Change package name for Android in React Native
问题描述
我用react-native init MyApp
初始化了一个新的React Native应用程序.
这创建了一个带有包com.myapp
的Android项目.
I used react-native init MyApp
to initialise a new React Native app.
This created among others an Android project with the package com.myapp
.
更改此软件包名称的最佳方法是什么,例如更改为com.mycompany.myapp
?
What's the best way to change this package name, for example to: com.mycompany.myapp
?
我尝试在AndroidManifest.xml
中更改它,但是它创建了其他错误,因此我认为这不是可行的方法.
I tried changing it in AndroidManifest.xml
but it created other errors, so I'm assuming it's not the way.
有什么主意吗?
推荐答案
我从以下位置重命名了该项目的子文件夹: android/app/src/main/java/MY/APP/ OLD_ID /"到:" android/app/src/main/java/MY/APP/ NEW_ID /"
I've renamed the project' subfolder from: "android/app/src/main/java/MY/APP/OLD_ID/" to: "android/app/src/main/java/MY/APP/NEW_ID/"
然后手动切换新旧程序包ID:
Then manually switched the old and new package ids:
在: android/app/src/main/java/MY/APP/NEW_ID/MainActivity.java :
package MY.APP.NEW_ID;
在 android/app/src/main/java/MY/APP/NEW_ID/MainApplication.java 中:
package MY.APP.NEW_ID;
在 android/app/src/main/AndroidManifest.xml 中:
package="MY.APP.NEW_ID"
在 android/app/build.gradle 中:
applicationId "MY.APP.NEW_ID"
在 android/app/BUCK 中:
android_build_config(
package="MY.APP.NEW_ID"
)
android_resource(
package="MY.APP.NEW_ID"
)
最终
Gradle'清理(在/android 文件夹中):
./gradlew clean
这篇关于在React Native中更改Android的软件包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!