React Native XCode 项目产品存档因架构 arm64 的重复符号而失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42021796/
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
React Native XCode Project Product Archive Fails with duplicate symbols for architecture arm64
提问by Kaiwen Huang
Strangely, I can't seem to get Archive to work in XCode but the build succeeds without the errors on duplicate symbols if I do not attempt to Archive but simply build a release version. The project builds properly on devices as well.
奇怪的是,我似乎无法让存档在 XCode 中工作,但是如果我不尝试存档而只是构建发布版本,则构建成功而不会出现重复符号的错误。该项目也可以在设备上正确构建。
I have searched up on this topic and tried disabling testability, and setting the 'No Common Blocks' in the project settings to NO as well but no luck so far.
我已经搜索了这个主题并尝试禁用可测试性,并将项目设置中的“No Common Blocks”设置为 NO 但到目前为止还没有运气。
The Project is a React Native 0.40 based project with CocoaPods installed as well. PodFile is this
该项目是一个基于 React Native 0.40 的项目,也安装了 CocoaPods。PodFile 是这个
# You Podfile should look similar to this file. React Native currently does not support use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# Change 'AirMapsExplorer' to match the target in your Xcode project.
target 'StreetSmart' do
pod 'React', path: '../node_modules/react-native', :subspecs => [
'Core',
'RCTActionSheet',
'RCTAnimation',
'RCTGeolocation',
'RCTImage',
'RCTLinkingIOS',
'RCTNetwork',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket'
]
pod 'GoogleMaps' # <~~ remove this line if you do not want to support GoogleMaps on iOS
# when not using frameworks we can do this instead of including the source files in our project (1/4):
# pod 'react-native-maps', path: '../../'
# pod 'react-native-google-maps', path: '../../' # <~~ if you need GoogleMaps support on iOS
end
XCode Version is 8.2.1, and the project file is opened via .xcworkspace since pods are installed.
XCode 版本为 8.2.1,由于安装了 Pod,项目文件通过 .xcworkspace 打开。
Would really appreciate any help or insight on this, been stuck at this for hours.
非常感谢您对此的任何帮助或见解,已在此停留数小时。
采纳答案by Kaiwen Huang
Finally solved the problem after finding a relevant issue on another react-native project here.
另一个反应本地项目寻找一个相关的问题后,终于解决了这个问题在这里。
The answer is that there is two copies of React Native in the Xcode project, one from CocoaPods and another as a subproject. Just remove all modules that were already declared in Podfile under the Libraries
inside Xcode and the error goes away after a clean and re-try.
答案是Xcode项目中有两份React Native,一份来自CocoaPods,另一份作为子项目。只需删除Libraries
内部 Xcode下 Podfile 中已经声明的所有模块,清理并重试后错误就会消失。
What's interesting about this issue is that all builds in Debug and Release works but it fails when attempting to Archive the project for distribution.
这个问题的有趣之处在于,所有在 Debug 和 Release 中的构建都可以工作,但在尝试将项目存档以进行分发时却失败了。
[Update 2 May 2017]
[2017 年 5 月 2 日更新]
The solution I described above can cause debug-time errors when you run your code with react-native run-ios/android
though it allows the project to be successfully archived.
我上面描述的解决方案在您运行代码时可能会导致调试时错误,react-native run-ios/android
尽管它允许成功归档项目。
An alternative method is to remove those duplicate modules that exist both in Libraries
and Podfile
from thePodfile
declaration instead of the Libraries
folder. And of course run the relevant pod commands, clean your project etc.
另一种方法是,以除去存在于这两个重复的模块Libraries
和Podfile
从所述Podfile
声明的代替Libraries
文件夹。当然,运行相关的 pod 命令,清理你的项目等。
Doing this allowed my code to archive and also run without debug-time errors
这样做允许我的代码存档并运行而没有调试时错误
回答by stueynet
So I did even more research into this and the workaround is actually much simpler. Or at least it was in my case. The problem is that when you declare React in the podfile, the Pods xcodeproject gets a React target as part of the pod install
process. Having this target in the Pods project is what causes the error when you Archive. So the fix is to remove the target.
所以我对此进行了更多研究,解决方法实际上要简单得多。或者至少在我的情况下是这样。问题在于,当您在 podfile 中声明 React 时,Pods xcodeproject 会在该pod install
过程中获取一个 React 目标。在 Pods 项目中有这个目标是导致存档时出错的原因。所以解决方法是删除目标。
The problem with removing the target in xCode is that this actually edits project.pbxproj file within the Pods folder which is not in version control. So while the build will archive once you do this, if you deploy from anywhere other than the machine that manually removed it, it will still fail. So the solution is to add this post install command to the bottom of your podfile:
在 xCode 中删除目标的问题在于,这实际上编辑了 Pods 文件夹中的 project.pbxproj 文件,该文件不受版本控制。因此,虽然构建将在您执行此操作后存档,但如果您从手动删除它的机器以外的任何地方进行部署,它仍然会失败。因此,解决方案是将此 post install 命令添加到 podfile 的底部:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end
This simply loops through all the pods to be installed and removes the target for the React one. This way anywhere that builds the project, will also remove the target. Now when you build to Archive it will not fail.
这只是遍历所有要安装的 pod,并删除 React 的目标。这样,任何构建项目的地方也将删除目标。现在,当您构建存档时,它不会失败。
回答by ofundefined
I solved this issue by the following: (ref.: https://github.com/react-community/react-native-maps/issues/718)
我通过以下方式解决了这个问题:(参考:https: //github.com/react-community/react-native-maps/issues/718)
- Open Xcode > Pods > Targets Support Files > Pods-{TARGET-NAME} find
"OTHER_LDFLAGS" and removeonly
-ObjC
in these two files:
- 打开 Xcode > Pods > Targets Support Files > Pods-{ TARGET-NAME} 找到“OTHER_LDFLAGS”并只 在这两个文件中删除
-ObjC
:
Pods-{TARGET-NAME}.release.xcconfig
e
Pods-{TARGET-NAME}.debug.xcconfig
Pods-{TARGET-NAME}.release.xcconfig
电子
Pods-{TARGET-NAME}.debug.xcconfig
- Go to project main target> Build
Settings > Other Linker Flags: Make sure no
-ObjC
is left in the value I deleted the build/Build folder in ios and run your project again.
- 转到项目主要目标> 构建设置 > 其他链接器标志:确保没有
-ObjC
留下值我删除了 ios 中的构建/构建文件夹并再次运行您的项目。
It works now.
它现在有效。
Side effects from the link above: the app may become larger as there may be duplicated symbols in it.
上面链接的副作用:应用程序可能会变大,因为其中可能有重复的符号。
Hope it can help you.
希望它可以帮助你。