Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CocoaPods Support #279

Closed
victorkvarghese opened this issue Mar 7, 2019 · 29 comments
Closed

CocoaPods Support #279

victorkvarghese opened this issue Mar 7, 2019 · 29 comments
Labels
wontfix This will not be worked on

Comments

@victorkvarghese
Copy link

Hi,

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

Would be great to see Pods Support!

@radex
Copy link
Collaborator

radex commented Mar 7, 2019

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

@victorkvarghese
Copy link
Author

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.

@vdlindenmark
Copy link
Contributor

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.

@jaysonjh
Copy link

Need CocoaPods Support!

@vdlindenmark
Copy link
Contributor

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

@radex
Copy link
Collaborator

radex commented Mar 22, 2019

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/

@vdlindenmark
Copy link
Contributor

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

@jaysonjh
Copy link

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.

@dehlen
Copy link

dehlen commented Apr 1, 2019

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.

@dehlen
Copy link

dehlen commented Apr 1, 2019

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: dm-Mobile-SE-Developer@979bea0 and dm-Mobile-SE-Developer@02838c0.

@radex
Copy link
Collaborator

radex commented Apr 1, 2019

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/WatermelonDB@979bea0 and dm-Mobile-SE-Developer/WatermelonDB@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?

@dehlen
Copy link

dehlen commented Apr 1, 2019

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

@dehlen
Copy link

dehlen commented Apr 2, 2019

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.

@radex
Copy link
Collaborator

radex commented Apr 2, 2019

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)

@stigi
Copy link

stigi commented May 15, 2019

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 🤞

@radex
Copy link
Collaborator

radex commented May 23, 2019

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 :)

@stigi
Copy link

stigi commented May 23, 2019

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

@radex
Copy link
Collaborator

radex commented May 23, 2019

@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...

@jakebloom
Copy link
Contributor

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

@radex
Copy link
Collaborator

radex commented Oct 22, 2019

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

@fungilation
Copy link

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.

@radex
Copy link
Collaborator

radex commented Oct 24, 2019

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

@fungilation
Copy link

fungilation commented Oct 24, 2019

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

@fmorau
Copy link

fmorau commented Dec 2, 2019

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

@radex
Copy link
Collaborator

radex commented Dec 2, 2019

@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

@Mahmoud-Masri
Copy link

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?

@chrise86
Copy link

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

@radex
Copy link
Collaborator

radex commented Mar 12, 2020

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

@stale
Copy link

stale bot commented Sep 11, 2020

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.

@stale stale bot added the wontfix This will not be worked on label Sep 11, 2020
@radex radex closed this as completed Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests