Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using static libraries in Swift with CocoaPods fails for Realm

Since Xcode 9 it is possible to use static libraries by omitting the use_frameworks! flag in the Podfile. However, when used with the Pod RealmSwift this results in the following error:

[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `RealmSwift` depends upon `Realm`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

Sadly, the proposed solution with use_modular_headers! does not work.

Other things I have tried include:

  • Using the latest Realm version (3.15.0)
  • Use the Objective C version and add Swift support, this won't build and give a module not found error in the RLMSupport.swift file .
  • Adding a bridging header for the Objective C version.
  • Endless clean, rebuild, Xcode relaunches and Derived Data folder cleaning.

It would not be preferable to circumvent CocoaPods and have this dependency be installed in a separate way, since that would make updating a more complex process. I hope there is a solution that works with CocoaPods, Realm and Swift.

like image 408
TmKVU Avatar asked May 13 '19 14:05

TmKVU


2 Answers

I did the job doing following:

pod 'RealmSwift', '~> 3.17', :modular_headers => true
pod 'Realm', '~> 3.17', :modular_headers => true
like image 111
atereshkov Avatar answered Sep 18 '22 12:09

atereshkov


As far as I can tell adding use_modular_headers! to top of Podfile works.

Adding s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } to .podspec doesn't work as far as I can tell. (Cocoapods 1.6.0-beta.2)

example:

target 'Opportunity' do
    use_modular_headers!

end
like image 33
davis Avatar answered Sep 18 '22 12:09

davis