在 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 文件夹中):
Gradle' cleaning in the end (in /android folder):
./gradlew clean
这篇关于在 React Native 中更改 Android 的包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!