Search code examples
ioscocoapodsxcframework

XCFramework asset bundle via Cocoapods


I have a framework that contains its own assets. I need to distribute this framework in a closed source manner, and it must be accessible via React Native as well so i want to distribute via Cocoapods. I created an XCFramework to close source the code and i wrote the following podspec:

Pod::Spec.new do |s|
  s.name             = "MyFramework"
  s.version          = "1.0.0"
  s.summary          = "Example"
  s.description      = "Example"
  s.homepage         = "http://example.com/"
  s.license          = "Private"
  s.author           = { "Example" => "[email protected]" }
  s.source           = { :http => 'https://example.com/MyFramework.xcframework.zip' }

  s.platform     = :ios, '16.4'
  s.requires_arc = true
  s.swift_version = '5.0'

  s.vendored_frameworks = 'MyFramework.xcframework'

end

My code accesses its assets like so:

Image("image-name", bundle: Bundle(for: MyFrameworkClass.self))

My library pulls in and works, with the exception that it is missing the asset bundle from the framework. How can i modify my podspec so that cocoapods pulls in and links my assets?


Solution

  • i resolved this by adding

    s.preserve_paths = 'MyFramework.xcframework'
    

    to my podspec. After adding this, the assets.car is retained in the .xcframework brought in by cocoapods.