Watermelondb: CocoaPods Support

Created on 7 Mar 2019  ·  29Comments  ·  Source: Nozbe/WatermelonDB

Hi,

is it possible to integrate this library using Pods?
All of my other libs use Pods.

Would be great to see Pods Support!

wontfix

Most helpful comment

Yep, please do! I just did a quick search and Artsy seems to have made a tutorial on how to set up a CocoaPod:
http://artsy.github.io/blog/2018/04/17/making-a-components-pod/

All 29 comments

@victorkvarghese not currently, but it should be very easy to do if you'd like to contribute :)

Im not that well versed in iOs side.

i tried adding podspec manually to the folder. pod install worked .. But the app crashes saying

[DB] Uh-oh. Database failed to load, we're in big trouble TypeError: Cannot read property 'initialize' of undefined

Not sure whether it's a native issue or my JS code.

Would be nice if WatermelonDB is supporting CocoaPods, react-native is making the default of it.
I don't know how to intergrade it, so can't help with a PR.

Need CocoaPods Support!

@jaysonjh the idea of open-source is that if you really need something you could provide a PR. :)

Yep, please do! I just did a quick search and Artsy seems to have made a tutorial on how to set up a CocoaPod:
http://artsy.github.io/blog/2018/04/17/making-a-components-pod/

I don't know how to setup CocoaPods, but the tutorial looks easy. Maybe I try it this week. :-) Thanks for sharing the tutorial!

I don't know how to setup CocoaPods, but the tutorial looks easy. Maybe I try it this week. :-) Thanks for sharing the tutorial!

I write this pod file, it can be build.

require "json"

Pod::Spec.new do |s|
  # NPM package specification
  package = JSON.parse(File.read(File.join(File.dirname(__FILE__), "package.json")))

  s.name         = "WatermelonDB"
  s.version      = package["version"]
  s.summary      = package["description"]
  s.homepage     = package["homepage"]
  s.license      = package["license"]
  s.author       = package["author"]
  s.platform     = :ios, "8.0"
  s.source       = { :git => "https://github.com/Nozbe/WatermelonDB.git", :tag => "master" }
  s.source_files = "native/ios/**/*.{h,m,swift}" #, "native/ios/WatermelonDB/SupportingFiles/*.modulemap"
  s.public_header_files = "native/ios/**/*.h"
  # s.preserve_path = "native/ios/WatermelonDB/SupportingFiles/WatermelonDB.modulemap"
  # s.xcconfig = { "SWIFT_INCLUDE_PATHS" => "$(PODS_ROOT)/native/ios/WatermelonDB/SupportingFiles"}
  s.dependency "React"
end

The pod will auto create the WatermelonDB-umbrella.h include FMDB.h. So must modify the Bridging.h

//#import "../FMDB/src/fmdb/FMDB.h"
#import <React/RCTBridgeModule.h>

But in xcodeproject, remove this not build success.May be you can try to fix to integrate by xcodeproject.

We are currently maintaining a fork with CocoaPods support. Would love to contribute back however the fork has some other adjustments (gradle support etc.) which would make integrating hard atm. Here is the podspec which works for us: https://github.com/dm-Mobile-SE-Developer/WatermelonDB/blob/715ae494ff7956eea9bd7052281d791fd914536b/WatermelonDB.podspec. Currently this is not a priority. We might clean up the branch in the future and make a PR, however If someone needs CP support earlier I'd love to see this happen and would support if needed.

The podspec needs to be added to the package.json/make.js script so it will be included in the artifact published to npmjs.org. Also we changed the native/ios/WatermelonDB/SupportingFiles/Bridging.h header file to include the FMDB library as a pod, see: https://github.com/dm-Mobile-SE-Developer/WatermelonDB/commit/979bea02d841bfdcaed6716c8204e01146e693e1 and https://github.com/dm-Mobile-SE-Developer/WatermelonDB/commit/02838c0370bd9cbaa9f01938bd0fb4ebed5755c8.

Thanks for the advice @dehlen !

Also we changed the native/ios/WatermelonDB/SupportingFiles/Bridging.h header file to include the FMDB library as a pod, see: dm-Mobile-SE-Developer@979bea0 and dm-Mobile-SE-Developer@02838c0.

This makes total sense for CocoaPods use, but I don't want to force people to use CocoaPods, since this is not a standard / not completely understandable to many in React Native community… It would be great to maintain compatibility with both. Isn't there a preprocessor macro can_include to select whichever FMDB header is available?

Something like this might work however this is not tested and i wrote it on my iPhone so i might have some syntax issues I am not seeing :)

#if __has_include(<Framework/Framework.h>)
#import <Framework/Framework.h>
#else
#import "Framework.h"
#endif

Btw. I am not sure if this would work but wouldn't it be possible to add "../FMDB/src/fmdb/**" to the Header Search Paths of the WatermelonDB xcodeproj ? This way the import could be changed to #import "FMDB.h" either way and it would be a much nicer solution imo. However again I do not have time to try this out at the moment.

If __has_include actually works, I'd prefer it that way. Personally, I think messing with header search paths is bad and causes a ton of issues (as many people experience with React Native's search path mess)

I jumped through many hoops to get this right, but here's the patch I'm currently using that contains a working podspec file. It contains a couple of other fixes, namely importing React and FMDB as modules in swift.
https://gist.github.com/stigi/5c972cd1d47b8486633ce29cbf9469d6

There are a couple things to consider:

I'm planning on opening a PR eventually, but not sure if the RN 0.59.3 dependency is blocking.

Good luck 🤞

You need to set use_frameworks! in your pod file

Why? @stigi This shouldn't be necessary with modern Swift.

but not sure if the RN 0.59.3 dependency is blocking

It's not :)

@radex are you referring to using use_modular_headers! instead of use_frameworks!?

@stgi I'm not 100% sure if use_modular_headers is necessary (though it might be), but it's no longer best practice to use_frameworks!, because every Pod then generates an iOS dynamic framework, and each of which adds extra time to app launch time. It's better to statically link dependencies, which has been possible with CocoaPods for a few versions...

This'd be fantastic to get in now that RN >= 0.60 has autolinking!

@jakebloom PRs welcome! :) Looks like most of the work is done, just needs to be brought all together

On RN 0.61.2. Doc's react-native link @nozbe/watermelondb won't build, 10 errors on Could not build module 'Foundation':
image

For pods, using @stigi 's gist in https://github.com/Nozbe/WatermelonDB/issues/279#issuecomment-492734700, it's close but won't build with 1 error in native/ios/WatermelonDB/DatabaseBridge.swift - No such module 'React':

image

in Podfile, I tried both pod 'FMDB', :modular_headers => true and use_frameworks!. Same thing in Xcode build, fail on No such module 'React'.

So I'm stuck, can't build WatermelonDB at all on iOS. Tried both v0.14.1 and latest v0.15.0-5.

@fungilation i think the React import lacks a #canImport directive

That doesn't help, if I don't add the import React line as in @stigi 's gist in DatabaseBridge.swift, RCTPromiseResolveBlock and any RCT* variables to follow would err on build.

I'm on Xcode 11.1 and macOS Catalina

@radex eventually you have not added support of cocoapods? :)

@chelovekdrakon Please contribute! I'm not using CocoaPods for React dependencies at this moment and no one sent a working pull request for adding a Podfile yet

On RN 0.61.2. Doc's react-native link @nozbe/watermelondb won't build, 10 errors on Could not build module 'Foundation':
image

For pods, using @stigi 's gist in #279 (comment), it's close but won't build with 1 error in native/ios/WatermelonDB/DatabaseBridge.swift - No such module 'React':

image

in Podfile, I tried both pod 'FMDB', :modular_headers => true and use_frameworks!. Same thing in Xcode build, fail on No such module 'React'.

So I'm stuck, can't build WatermelonDB at all on iOS. Tried both v0.14.1 and latest v0.15.0-5.

Same here, were you able to solve it?

Also struggling to get this to build on RN 0.61.5, anyone managed it?

search react-native projects for CocoaPods support and you'll see what changes need to be made. React imports need to be slightly different for it to compile

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings