React Native XCode Project Product Archive Fails with duplicate symbols for architecture arm64

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

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.

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.

The Project is a React Native 0.40 based project with CocoaPods installed as well. PodFile is this

# 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'  # 

XCode Version is 8.2.1, and the project file is opened via .xcworkspace since pods are installed.

Would really appreciate any help or insight on this, been stuck at this for hours.

回答1:

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.

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.

[Update 2 May 2017]

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.

An alternative method is to remove those duplicate modules that exist both in Libraries and Podfile from the Podfile declaration instead of the Libraries folder. And of course run the relevant pod commands, clean your project etc.

Doing this allowed my code to archive and also run without debug-time errors



回答2:

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.

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:

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.



回答3:

I hope this helps someone. I had to remove all subspecs for it to work:

https://github.com/airbnb/react-native-maps/issues/943#issuecomment-279882262



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!