Search code examples
iosxcodecocoapodsxcode12

Xcode 12, framework build failed, cocoapods, arm64


I try to generate a framework from a podspec using cocoapods-packager:

pod package MyCore.podspec --embedded --subspecs=SDK

In Xcode 11, everything is fine, but on Xcode 12 I get follow error:

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: Pods/build/package.a and Pods/build-sim/package.a have the same architectures (arm64) and can't be in the same fat output file

The solution that suggested here: Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 to add:

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

doesn't work for me. This my be related to fact that I use dependencies? Anyone have an idea how to fix this issue?

Podspec: 
#
# Be sure to run `pod lib lint **.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name            = "MyCore"
  s.version         = "9.1.1.2360"
  s.summary         = "A short description of ***."
  s.homepage        = "https://github.com/***/***"
  s.license         = 'Private'
  s.author          = { "***" }
  s.source          = { :git => "***", :tag => s.version.to_s }
  
  s.platform        = :ios, '10.0'
  s.requires_arc    = true
  
  s.module_name     = '***'
  s.default_subspec = 'Core'
  s.static_framework = true
  s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
  s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

  s.subspec 'Core' do |ss|
      ss.source_files = 'Pod/Classes/**/*.{h,m,c}'
      ss.resources =     ['Pod/CoreData/DrivePal.{xcdatamodeld,xcmappingmodel}', 'Pod/CoreData/mapping_*.xcmappingmodel', 'Pod/Assets/**/*.{csv,storyboard}']
      ss.resource_bundle = { 
        '**Core_CoreData' => ['Pod/CoreData/DrivePal.{xcdatamodeld,xcmappingmodel}', 'Pod/CoreData/mapping_*.xcmappingmodel','Pod/Assets/**/crash*.txt'],
      }
      ss.preserve_paths = ['Pod/CoreData/*.xcdatamodeld', 'Pod/CoreData/*.xcmappingmodel']
      ss.frameworks = 'CoreLocation', 'CoreBluetooth', 'CoreMotion', 'CoreData', 'AVFoundation', 'SystemConfiguration', 'Foundation'
      ss.library = 'z'

      ss.dependency 'CocoaLumberjack', '~> 3.5.3'
      ss.dependency 'Mantle', '2.1.4'
      ss.dependency 'MTLManagedObjectAdapter', '~> 1.0.3'

      ss.dependency 'AFNetworking/Serialization', '~> 3.2.1'
      ss.dependency 'AFNetworking/Reachability', '~> 3.2.1'
      ss.dependency 'AFNetworking/NSURLSession', '~> 3.2.1'

      ss.test_spec '***CoreTests' do |core_tests|
        core_tests.source_files = 'Pod/***CoreTests/**/*.{h,m}'
        core_tests.resources = 'Pod/***CoreTests/**/*.{json,txt}'
      end
  end
  
  # Core is copy of SDK
  s.subspec 'SDK' do |sdk|
      sdk.source_files = 'Pod/Classes/**/*.{h,m,c}'
      sdk.exclude_files = ['Pod/***CoreTests/*']
      sdk.resources =     ['Pod/CoreData/DrivePal.{xcdatamodeld,xcmappingmodel}', 'Pod/CoreData/mapping_*.xcmappingmodel']
      sdk.resource_bundle = {
          '***Core_CoreData' => ['Pod/CoreData/DrivePal.{xcdatamodeld,xcmappingmodel}','Pod/CoreData/mapping_*.xcmappingmodel','Pod/Assets/**/crash*.txt'],
      }
      sdk.compiler_flags = '-DTESTING=0'
      sdk.preserve_paths = ['Pod/CoreData/*.xcdatamodeld', 'Pod/CoreData/*.xcmappingmodel']
      sdk.frameworks = 'CoreLocation', 'CoreBluetooth', 'CoreMotion', 'CoreData', 'AVFoundation', 'SystemConfiguration', 'Foundation'
      sdk.library = 'z'
      
      sdk.dependency 'CocoaLumberjack', '~> 3.5.3'
      sdk.dependency 'Mantle', '2.1.4'
      sdk.dependency 'MTLManagedObjectAdapter', '~> 1.0.3'

      sdk.dependency 'AFNetworking/Serialization', '~> 3.2.1'
      sdk.dependency 'AFNetworking/Reachability', '~> 3.2.1'
      sdk.dependency 'AFNetworking/NSURLSession', '~> 3.2.1'

      sdk.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64', 'ONLY_ACTIVE_ARCH' => 'YES' }
      sdk.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64','ONLY_ACTIVE_ARCH' => 'YES' }

      sdk.public_header_files = [****]
    end

end

Update: if I add --exclude-deps flag, it works, but my framework doesn't include dependencies.


Solution

  • Solved by modifying the local cocoapods-packager source ruby code. Modified .rb file's path:

    /Library/Ruby/Gems/2.6.0/gems/cocoapods-packager-1.5.0/lib/cocoapods-packager/pod_utils.rb (path may be different /Users/USER/.rvm/gems/ruby-2.6.3/gems/cocoapods-packager-1.5.0/lib/cocoapods-packager/pod_utils.rb)

    unless static_installer.nil?
      static_installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
          config.build_settings['GCC_GENERATE_DEBUGGING_SYMBOLS'] = 'NO'
          config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' // <-- inserted here
        end
      end
      static_installer.pods_project.save
    end