Problem building ios framework with subspec for cocoapods

2.2k Views Asked by At

This is my SDK's podspec:

#
#  Be sure to run `pod spec lint Core.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|
  s.name             = "TiendeoCore"
  s.version          = "0.1.10"
  s.summary          = "Tiendeo Core"
  s.homepage         = "https://www.tiendeo.com"
  s.license          = 'Custom'
  s.author           = { "Tiendeo" => "[email protected]" }
  s.platform         = :ios, '10.0'

  #REMOTE 
s.source = { "http" => "https://tiendeo.jfrog.io/tiendeo/pods/TiendeoCore/TiendeoCore-0.1.10.zip" }

  #LOCAL#   s.source = { :git => "https://gitlab.tiendeo.com/ios/core-ios.git", :tag => s.version }
  s.dependency "Governor", "~> 0.2.5"
  s.dependency "AlamofireObjectMapper", "~> 5.2"
  s.dependency "Alamofire", "~> 4.8"
  s.dependency "RealmSwift", "~> 3.11.1"
  s.dependency "RxSwift", "~> 4.2.0"
  s.default_subspec = 'Lite'

  s.subspec 'Lite' do |lite|
    lite.name = "Lite"
    #REMOTE 
lite.framework = "TiendeoCore"
    #REMOTE 
lite.vendored_frameworks = 'TiendeoCore.framework'
     #LOCAL#     lite.source_files     = ["Source/**/*.swift", "Source/Core.h"]
     #LOCAL#     lite.public_header_files = ["Source/Core.h"]
     #LOCAL#     lite.resource_bundles = {
     #LOCAL#       'TiendeoCore' => ['Source/**/*.{xib,png,jpg,json,xcdatamodeld,xcdatamodel,xcassets,ttf,lproj}']
     #LOCAL#     }
  end

  s.subspec 'Full' do |full|
    full.name = "Full"
    #REMOTE 
full.framework = "TiendeoCore"
    #REMOTE 
full.vendored_frameworks = 'TiendeoCore.framework'

    #LOCAL#     full.source_files     = ["Source/**/*.swift", "Source/Core.h"]
    #LOCAL#     full.public_header_files = ["Source/Core.h"]
    #LOCAL#     full.resource_bundles = {
    #LOCAL#       'TiendeoCore' => ['Source/**/*.{xib,png,jpg,json,xcdatamodeld,xcdatamodel,xcassets,ttf,lproj}']
    #LOCAL#     }
    full.xcconfig = {
         'OTHER_SWIFT_FLAGS' => '$(inherited) -DFULLTIENDEOCORE'
    }
    full.dependency "TiendeoAuth", "~> 0.0.6"
    full.dependency "FacebookCore", '~> 0.4.0'
  end


end

I'm building a TiendeoCore.framework for upload it to cocoapods with the command (I have an script that build .framework and copy the simulator's architectures, I'm showing the main commands of the script):

xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphoneos ONLY_ACTIVE_ARCH=NO ARCHS='arm64 armv7' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

The upload of the framework to cocoapods finish successfully, but when I install the version on my project (build and run ok), the app throws this error on start:

dyld: Library not loaded: @rpath/Bolts.framework/Bolts
  Referenced from: /private/var/containers/Bundle/Application/43993CDF-61A7-405F-BA37-6FAD4B8B5FFF/ViewerPro-Demo.app/Frameworks/TiendeoCore.framework/TiendeoCore
  Reason: image not found

My podspec has two subspec (lite and full), I'm installing the lite version by default but at runtime TiendeoCore.framworks throws that needs a dependency of full subspec, Facebook in this case.

In my code, I have a preprocessing flag called FULLTIENDEOCORE to enclose source code that use dependencies of full version:

#if FULLTIENDEOCORE
import TiendeoAuth
#endif

So if the Flag is declared in OTHER_SWIFT_FLAGS then the code will be executed (this flag is added on the podspec in the full subspec).

I don't know what I'm missing.

Thanks in advance.

1

There are 1 best solutions below

3
Paul Beusterien On

Subspecs are designed to be merged so that consumers can choose a subset of the available subspecs. By using the same name for both vendored_frameworks, it is likely that the wrong one is getting referenced.

If that doesn't help you may want to investigate the current open subspec issues.