Xcode 发布模式下,目标为模拟器时构建报错:Undefined symbols for architecture i386

Objective C 2021-03-23 阅读 319 评论 0

问题描述

Xcode 的项目,尝试在 Release 模式下运行虚拟机,编译项目的时候出现以下错误:

ld: warning: ignoring file /develop/O2O/ios/Pods/AMapFoundation/AMapFoundationKit.framework/AMapFoundationKit, missing required architecture i386 in file /develop/O2O/ios/Pods/AMapFoundation/AMapFoundationKit.framework/AMapFoundationKit (3 slices)
ld: warning: ignoring file /develop/O2O/ios/Pods/AMapSearch/AMapSearchKit.framework/AMapSearchKit, missing required architecture i386 in file /develop/O2O/ios/Pods/AMapSearch/AMapSearchKit.framework/AMapSearchKit (3 slices)
ld: warning: ignoring file /develop/O2O/ios/Pods/AMap3DMap/MAMapKit.framework/MAMapKit, missing required architecture i386 in file /develop/O2O/ios/Pods/AMap3DMap/MAMapKit.framework/MAMapKit (3 slices)
ld: warning: could not create compact unwind for _DES_read_password: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _DES_read_2passwords: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _RAND_load_file: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _RAND_write_file: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _ERR_print_errors_cb: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _ERR_print_errors: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PEM_SealUpdate: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PEM_X509_INFO_write_bio: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PEM_read_bio_PrivateKey: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _process_pci_value: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PKCS7_verify: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _PKCS7_decrypt: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _read_string_inner: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _pkey_GOST01cp_encrypt: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _pkey_GOST01cp_decrypt: stack subl instruction is too different from dwarf stack size
Undefined symbols for architecture i386:
  "_OBJC_METACLASS_$_AMapRequestReformer", referenced from:
      _OBJC_METACLASS_$_AMapLocationUploadRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
      _OBJC_METACLASS_$_AMapLocationUploadSwitchRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_METACLASS_$_AMapRESTRequestReformer", referenced from:
      _OBJC_METACLASS_$_AMapLocationDistrictRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
      _OBJC_METACLASS_$_AMapLocationPOIKeywordsRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
      _OBJC_METACLASS_$_AMapLocationPOIAroundRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_AMapCoordinateConvert", referenced from:
      _AMapLocationCoordinateConvert in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapAnalyticsManager", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapFoundationUtility", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapFoundationCompression", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_MAAnnotationView", referenced from:
      objc-class-ref in RCTAMap3DManager.o
  "_AMapLogVersion30", referenced from:
      -[AMapReGeocodeManager requestReGeocodeInfoWithCoordinate:language:timeout:handler:] in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_MACircleRenderer", referenced from:
      objc-class-ref in RCTAMap3DManager.o
  "_AMapAuthUpdateNotification", referenced from:
      -[AMapLocationManager init] in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_AMapAuthKeyManifest", referenced from:
      -[AMapLocationManager handleCloudConfigs:] in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_MAPolylineRenderer", referenced from:
      objc-class-ref in RCTAMap3DManager.o
  "_AMapRequestHttpMethodPost", referenced from:
      -[AMapLocationDistrictRequestReformer method] in AMapLocationKit(AMapLocationKit-i386-master.o)
      -[AMapLocationPOIKeywordsRequestReformer method] in AMapLocationKit(AMapLocationKit-i386-master.o)
      -[AMapLocationPOIAroundRequestReformer method] in AMapLocationKit(AMapLocationKit-i386-master.o)
      -[AMapLocationUploadRequestReformer method] in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapServicesConfig", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_METACLASS_$_MAMultiPolyline", referenced from:
      _OBJC_METACLASS_$_CustomMAMultiPolyline in CustomMAMultiPolyline.o
  "_OBJC_METACLASS_$_MAPointAnnotation", referenced from:
      _OBJC_METACLASS_$_MANaviAnnotation in MANaviAnnotation.o
      _OBJC_METACLASS_$_MyMAPointAnnotation in MyMAPointAnnotation.o
  "_OBJC_CLASS_$_AMapReGeocodeSearchRequest", referenced from:
      objc-class-ref in RCTAMapManager.o
  "_OBJC_CLASS_$_AMapRESTRequestReformer", referenced from:
      _OBJC_CLASS_$_AMapLocationDistrictRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
      _OBJC_CLASS_$_AMapLocationPOIKeywordsRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
      _OBJC_CLASS_$_AMapLocationPOIAroundRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapAnalyticsRequestReformer", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_kAMapNetworkReachabilityChangedNotification", referenced from:
      -[AMapLocationUploadManagerOld init] in AMapLocationKit(AMapLocationKit-i386-master.o)
      -[AMapLocationUploadManager registerNotificationObservers] in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapPOIKeywordsSearchRequest", referenced from:
      objc-class-ref in RCTAMapManager.o
  "_OBJC_CLASS_$_AMapRidingRouteSearchRequest", referenced from:
      objc-class-ref in RCTAMap3DManager.o
  "_OBJC_CLASS_$_AMapWeatherSearchRequest", referenced from:
      objc-class-ref in RCTAMapWeather.o
  "_MAMapRectZero", referenced from:
      +[CommonUtility mapRectUnion:count:] in CommonUtility.o
      +[CommonUtility mapRectForOverlays:] in CommonUtility.o
      +[CommonUtility minMapRectForMapPoints:count:] in CommonUtility.o
      +[CommonUtility minMapRectForAnnotations:] in CommonUtility.o
  "_OBJC_CLASS_$_AMapRequestReformer", referenced from:
      _OBJC_CLASS_$_AMapLocationUploadRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
      _OBJC_CLASS_$_AMapLocationUploadSwitchRequestReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_AMapRequestHttpMethodGet", referenced from:
      -[AMapLocationUploadSwitchRequestReformer method] in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_MAPolyline", referenced from:
      objc-class-ref in MANaviRoute.o
      objc-class-ref in CommonUtility.o
  "_OBJC_CLASS_$_MAPolygonRenderer", referenced from:
      objc-class-ref in RCTAMapManager.o
  "_OBJC_CLASS_$_AMapCloudConfig", referenced from:
      _OBJC_CLASS_$_AMapReGeocodeCacheConfig in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_MAPinAnnotationView", referenced from:
      objc-class-ref in RCTAMap3DManager.o
      objc-class-ref in RCTAMapManager.o
  "_OBJC_CLASS_$_MAMultiPolyline", referenced from:
      objc-class-ref in RCTAMap3DManager.o
      objc-class-ref in MANaviRoute.o
      _OBJC_CLASS_$_CustomMAMultiPolyline in CustomMAMultiPolyline.o
  "_OBJC_CLASS_$_AMapTMC", referenced from:
      objc-class-ref in MANaviRoute.o
  "_OBJC_CLASS_$_AMapGeoPoint", referenced from:
      objc-class-ref in RCTAMap3DManager.o
      objc-class-ref in RCTAMapManager.o
  "_OBJC_METACLASS_$_AMapCloudConfig", referenced from:
      _OBJC_METACLASS_$_AMapReGeocodeCacheConfig in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_METACLASS_$_AMapPostDataRequestReformer", referenced from:
      _OBJC_METACLASS_$_AMapLocationReGeocodeReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapSearchAPI", referenced from:
      objc-class-ref in RCTAMap3DManager.o
      objc-class-ref in RCTAMapWeather.o
      objc-class-ref in RCTAMapManager.o
  "_MAMapPointForCoordinate", referenced from:
      +[MANaviRoute replenishPolylineWithStart:end:] in MANaviRoute.o
      +[MANaviRoute calcPointWithStartPoint:endPoint:rate:] in MANaviRoute.o
      +[MANaviRoute calcDistanceBetweenCoor:andCoor:] in MANaviRoute.o
      ___42+[CommonUtility minMapRectForAnnotations:]_block_invoke in CommonUtility.o
      +[CommonUtility polylineHitTestWithCoordinate:mapView:polylinePoints:pointCount:lineWidth:] in CommonUtility.o
  "_OBJC_CLASS_$_AMapPOIAroundSearchRequest", referenced from:
      objc-class-ref in RCTAMapManager.o
  "_OBJC_METACLASS_$_MAMapView", referenced from:
      _OBJC_METACLASS_$_RCTAMap in RCTAMap.o
      _OBJC_METACLASS_$_RCTAMap3D in RCTAMap3D.o
  "_OBJC_CLASS_$_AMapFoundationReachability", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_MACoordinateForMapPoint", referenced from:
      ___35+[MANaviRoute naviRouteForWalking:]_block_invoke in MANaviRoute.o
      +[MANaviRoute naviRouteForSegment:index:] in MANaviRoute.o
      +[MANaviRoute calcPointWithStartPoint:endPoint:rate:] in MANaviRoute.o
      +[CommonUtility fetchPointPolylinePoints:mapView:index:selected:] in CommonUtility.o
  "_OBJC_CLASS_$_AMapNetworkManager", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapPostDataRequestReformer", referenced from:
      _OBJC_CLASS_$_AMapLocationReGeocodeReformer in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapFoundationAES", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapServices", referenced from:
      objc-class-ref in AppDelegate.o
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_AMapStatistics", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_OBJC_CLASS_$_MAPolygon", referenced from:
      objc-class-ref in RCTAMapManager.o
  "_OBJC_CLASS_$_MAPointAnnotation", referenced from:
      _OBJC_CLASS_$_MANaviAnnotation in MANaviAnnotation.o
      objc-class-ref in RCTAMapManager.o
      _OBJC_CLASS_$_MyMAPointAnnotation in MyMAPointAnnotation.o
  "_OBJC_CLASS_$_MAMultiColoredPolylineRenderer", referenced from:
      objc-class-ref in RCTAMap3DManager.o
  "_OBJC_CLASS_$_AMapCacheFileManager", referenced from:
      objc-class-ref in AMapLocationKit(AMapLocationKit-i386-master.o)
  "_MAMetersBetweenMapPoints", referenced from:
      +[MANaviRoute replenishPolylineWithStart:end:] in MANaviRoute.o
      +[MANaviRoute calcDistanceBetweenCoor:andCoor:] in MANaviRoute.o
      +[CommonUtility distanceToPoint:fromLineSegmentBetween:and:] in CommonUtility.o
  "_OBJC_CLASS_$_MAUserLocation", referenced from:
      objc-class-ref in RCTAMap3DManager.o
  "_OBJC_CLASS_$_MAMapView", referenced from:
      _OBJC_CLASS_$_RCTAMap in RCTAMap.o
      _OBJC_CLASS_$_RCTAMap3D in RCTAMap3D.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方法

在 Xcode 中选择:Project -> Build Settiongs -> Build active Architecture Only -> Release -> Yes。

设置 Build active Architecture Only 的 Release 为 Yes

Architectures 描述

在上图中,可以看到 Architectures 属性的值为 Standard Architectures (arm64, armv7),默认是这个值,当然我们也可以修改为其他值。我们可以在 iOS 的根目录下,运行以下命令,查看我们项目支持的虚拟机架构。

xcodebuild -showBuildSettings -scheme <application name> -sdk iphonesimulator | grep ARCHS

输出如下:

ARCHS = i386 x86_64
ARCHS_STANDARD = i386 x86_64
ARCHS_STANDARD_32_64_BIT = i386 x86_64
ARCHS_STANDARD_32_BIT = i386
ARCHS_STANDARD_64_BIT = x86_64
ARCHS_STANDARD_INCLUDING_64_BIT = i386 x86_64
ARCHS_UNIVERSAL_IPHONE_OS = i386 x86_64
VALID_ARCHS = i386 x86_64

执行以下命令,查看真机设备支持的架构:

xcodebuild -showBuildSettings -scheme <application name> -sdk iphoneos | grep ARCHS

输出如下:

ARCHS = armv7 arm64
ARCHS_STANDARD = armv7 arm64
ARCHS_STANDARD_32_64_BIT = armv7 arm64
ARCHS_STANDARD_32_BIT = armv7
ARCHS_STANDARD_64_BIT = arm64
ARCHS_STANDARD_INCLUDING_64_BIT = armv7 arm64
ARCHS_UNIVERSAL_IPHONE_OS = armv7 arm64
VALID_ARCHS = arm64 arm64e armv7 armv7s

Build Active Architecture Only 描述

这是一个 bool 值,它指定 Xcode 将为所有有效架构或仅针对当前正在运行该应用程序的架构,来构建项目。

BuildSetting 为模拟器

在 Debug 模式下,Build Active Architecture Only 默认为 Yes,这意味着Xcode将构建目标中指定的体系结构。Xcode将构建与Simulator兼容的体系结构,请参考上图。

对于发布模式,默认值为 No。Xcode将构建“有效体系结构”下指定的所有体系结构。

如果要将构建上传到Appstore,请确保 Xcode 仅生成特定于真机设备的架构,我们不能上传特定于模拟器的架构。

最后更新 2021-03-23