ios 如何更改 React Native 中的“Bundle Identifier”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36119754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:43:39  来源:igfitidea点击:

How to change the "Bundle Identifier" within React Native?

iosxcodereact-native

提问by delete

Starting a new react-native project, the xcode-project gots the bundle-identifier "org.reactjs.native.example.XYZApp". XYZ is the placeholder here for my real project name.

启动一个新的 react-native 项目,xcode-project 获得了包标识符“org.reactjs.native.example.XYZApp”。XYZ 是我真实项目名称的占位符。

Is there any way to change this bundle identifier on react-native side? Sure, I can change it in XCode. But this is not safe because it can be overriden when react-native will recreate the xcode-project, which could happen at any time, as well es when rebuilding the project.

有什么方法可以在 react-native 端更改此包标识符吗?当然,我可以在 XCode 中更改它。但这并不安全,因为它可以在 react-native 重新创建 xcode-project 时被覆盖,这可能随时发生,在重建项目时也可能发生。

回答by Wandawi Najeeb R

Based on the react-native version you are using there are bunch of files that have to be changed on both platforms (android and ios)

根据您使用的 react-native 版本,必须在两个平台(android 和 ios)上更改大量文件

List of files to edit:

要编辑的文件列表:

IOS

IOS

  1. [application_build_scheem].plist (this is a dict/xml file that contains keys that are used by default if no changesadded to project (react-native-cli init type of project)
  1. [application_build_scheem].plist(这是一个 dict/xml 文件,其中包含默认使用的键,如果没有向项目添加更改(react-native-cli init 类型的项目)

ANDROID

安卓

  1. strings.xml (change app_namekey value)
  2. manifest.xml (change packageattribute)
  3. build.gradle (change applicationIdvalue)
  4. MainActivity.java (change java class package)
  5. MainApplication.java (change java class package)
  1. strings.xml(更改app_name键值)
  2. manifest.xml(更改属性)
  3. build.gradle(更改applicationId值)
  4. MainActivity.java(更改java类
  5. MainApplication.java(更改java类

It's worth mentioning that there is an an npm module (https://www.npmjs.com/package/react-native-ci-tools) that does all of the above; use it and make life easy.

值得一提的是,有一个 npm 模块(https://www.npmjs.com/package/react-native-ci-tools)可以完成上述所有工作;使用它,让生活更轻松。

Update (6/Mar/2019)

更新 (6/Mar/2019)

Update Folder Paths:

更新文件夹路径:

We also need to change the folder paths to match new name -- change com.oldNameto com.newname.mobile, then change folder paths from app/src/java/com/oldName/to app/src/java/com/newname/mobile/.

我们还需要更改文件夹路径以匹配新名称 - 更改com.oldNamecom.newname.mobile,然后将文件夹路径从 更改app/src/java/com/oldName/app/src/java/com/newname/mobile/

回答by Kyle Johnson

For those who want a simple way to do exactly this I create react-native-app-id, It'll basically edit the files mentioned. react-native-ci-tools actually forked my code to produce a now outdated react-native-app-id-fixed , which won't work with the latest react native. Mine however will..

对于那些想要一种简单的方法来做到这一点的人,我创建了 react-native-app-id,它基本上会编辑提到的文件。react-native-ci-tools 实际上分叉了我的代码以生成现在过时的 react-native-app-id-fixed ,它不适用于最新的 react native。然而我的会..

https://github.com/kyle-ssg/react-native-app-id

https://github.com/kyle-ssg/react-native-app-id

usage is as easy as react-native-app-id com.foo.bar

使用很简单 react-native-app-id com.foo.bar

回答by Paachu

To update iOS bundle id -

更新 iOS 捆绑包 ID -

  • From terminal or command prompt navigate to react-native project folder and then go inside iOS folder.
  • enter command Open ProjectName.xcodeproj
  • 从终端或命令提示符导航到 react-native 项目文件夹,然后进入 iOS 文件夹。
  • 输入命令打开 ProjectName.xcodeproj

This command will open the project in Xcode where you need to update bundle identifier information of the app

此命令将在 Xcode 中打开您需要更新应用程序包标识符信息的项目

To update android package name follow below steps -

要更新 android 包名称,请按照以下步骤操作 -

  • Update folder structure inside “android/app/src/main/java/” folder based on your new package name e.g "com/companyName/appName"
  • Update package name inside MainActivity.java file
  • Update package name inside MainApplication.java file
  • Update package name inside /android/app/src/main/AndroidManifest.xml file
  • Update package name inside /android/app/BUCK file
  • Update package name inside /android/app/build.gradle file
  • 根据您的新包名称更新“android/app/src/main/java/”文件夹中的文件夹结构,例如“com/companyName/appName”
  • 更新 MainActivity.java 文件中的包名
  • 更新 MainApplication.java 文件中的包名
  • 更新 /android/app/src/main/AndroidManifest.xml 文件中的包名
  • 更新 /android/app/BUCK 文件中的包名
  • 更新 /android/app/build.gradle 文件中的包名

回答by Brijesh Shiroya

If you want to change bundle identifier in react-native project. You must have to change app identifier separately for both side android and ios.

如果您想在 react-native 项目中更改包标识符。您必须分别为 android 和 ios 更改应用程序标识符。

ios

ios

Select root project in xcode, select General tab, You can see Bundle identifier into identity section and change your new bundle identifier for ios application

在 xcode 中选择根项目,选择常规选项卡,您可以在身份部分看到捆绑标识符并更改 ios 应用程序的新捆绑标识符

android

安卓

  1. Goto your AndroidManifest.xml.
  2. Just place your cursor in the package name, don't select it just place it.
  3. Then press shift+F6(window)/F6 (mac) you will get a popup window, fill new identifier and select Rename package. It will change from everywhere in android studio.
  1. 转到您的 AndroidManifest.xml。
  2. 只需将光标放在包名称上,不要选择它,只需放置它。
  3. 然后按 shift+F6(window)/F6 (mac) 你会得到一个弹出窗口,填写新标识符并选择重命名包。它会在 android studio 的任何地方发生变化。

回答by Rodrigo

Even with react-native-app-id you must move the files to the new folder

即使使用 react-native-app-id,您也必须将文件移动到新文件夹

I ended using a npm task for upgrading, first upgrade then run the command for rename, move the android files to the correct path and re-link just in case

我结束使用 npm 任务进行升级,首先升级然后运行重命名命令,将 android 文件移动到正确的路径并重新链接以防万一

回答by Ben B

Edit the PRODUCT_BUNDLE_IDENTIFIERassociated with the project in ios/project.pbxproj. It is much safer to use XCode.

编辑PRODUCT_BUNDLE_IDENTIFIER与项目相关的ios/project.pbxproj使用 XCode 安全得多。

I know that the question asked to do it without XCode, for people keen on using Xcode, when inside your react native project:

我知道这个问题要求在没有 XCode 的情况下完成,对于热衷于使用 Xcode 的人,当在您的本机项目中时:

  1. xed iosOpen the ios folder in xcode
  2. Click the top left icon (project navigator)
  3. Click the root item in the left panel ProjectName
  4. In the center view, click General
  5. Under identity, change the Bundle identifier
  1. xed ios在xcode中打开ios文件夹
  2. 单击左上角的图标 ( project navigator)
  3. 单击左侧面板中的根项目 ProjectName
  4. 在中心视图中,单击 General
  5. 在 下identity,更改 Bundle 标识符

回答by Chris Geirman

Unfortunately not. In fact we were just discussing this today in the react Native Facebook group. https://m.facebook.com/groups/586400221495560?view=permalink&id=738954276240153&comment_id=739065029562411&notif_t=group_comment_reply&ref=m_notif

不幸的是没有。事实上,我们今天刚刚在 react Native Facebook 小组中讨论了这个问题。 https://m.facebook.com/groups/586400221495560?view=permalink&id=738954276240153&comment_id=739065029562411¬if_t=group_comment_reply&ref=m_notif

The best plan right now is to choose the 'd' option when upgrading to verify the files before allowing then to be overridden.

现在最好的计划是在升级时选择“d”选项以验证文件,然后再允许被覆盖。