Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

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

XCode Log

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...