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

Support React Native installed with CocoaPods #884

Open
afces1 opened this issue Feb 23, 2017 · 38 comments · May be fixed by #2554

Comments

@afces1
Copy link

commented Feb 23, 2017

Goals: adding RealmReact 1.0.2 project into XCode with pod install of react-native@0.42.0.rc-3 will not result in compilation failure.

Expected results: success app build using RealmReact project with react-native@0.42.0.rc-3 inside XCode project.

Actual results: compilation failure on RealmReact.mm: 'React/RCTBridgeDelegate.h' file not found in RCTBridge.h. This is most likely due to the iOS header breaking change introduced in react-native@0.40.0 where React Native headers are expected to be enclosed in angle brackets, e.g. <React/RCTBridge.h>. Previously working on react-native@0.38.0 using same app code.

Steps to reproduce:
directory structure: $root/app, $root/rn (app XCode project is sibling of react native directory rn)

  1. npm install react@15.4.2 react-native@0.42.0.rc-3
  2. npm install realm@1.0.2
  3. include Yoga and React in Podfile:
    target 'app' do

use_frameworks!

pod 'Fabric'
pod 'Crashlytics'

React libraries

pod 'Yoga', :path => '../rn/node_modules/react-native/ReactCommon/yoga', :inhibit_warnings => true
pod 'React', :path => '../rn/node_modules/react-native', :subspecs => [
'Core',
'RCTActionSheet',
'RCTAnimation',
'RCTImage',
'RCTLinkingIOS',
'RCTText',
'RCTNetwork',
'RCTWebSocket',
], :inhibit_warnings => true

  1. pod install to install Yoga and React Native
  2. add RealmReact project into XCode from ../rn/node_modules/realm/react-native/ios/RealmReact.xcodeproj
  3. compile iOS app

Version: Realm 1.0.2 / Xcode 8.1 / OS X El Capitan 10.11.6

@makeitnew

This comment has been minimized.

Copy link

commented Feb 25, 2017

Try adding $(SRCROOT)/../../../../Pods/Headers/Public to the "Header Search Paths" for the RealmReact target.

To do this:

  1. Select the RealmReact project in your Xcode project
  2. Select the RealmReact Target
  3. Select "Header Search Paths" under the Build Settings tab
  4. Add the above path to the the list of existing search paths. The path above assumes both your Pods directory and your node_modules directory are at the top level of your project.
@non-binary non-binary added the T-Help label Feb 27, 2017
@non-binary

This comment has been minimized.

Copy link

commented Feb 27, 2017

Hi @afces1. Thanks for reaching out about this. I recommend trying @makeitnew's suggestion but please let us know if that doesn't work or if you have any other questions.

@fealebenpae

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2017

Hey @afces1,

I don't believe we support installing via CocoaPods - only with npm and the React Native CLI. I'll add this to our backlog.

In the mean time, the workaround proposed by @makeitnew seems viable.

@fealebenpae fealebenpae changed the title RealmReact.mm compilation failure: 'React/RCTBridgeDelegate.h' file not found in RCTBridge.h Support React Native installed with CocoaPods Feb 27, 2017
@natwales

This comment has been minimized.

Copy link

commented May 9, 2017

Not having success with @makeitnew's suggestion. Not sure if this is because my Pods/Headers/ folder set in my search paths are in fact empty or if I am missing a step. Also it appears the '/ios' parent folder is missing in the search path suggested, though that didn't change anything for me. Would love to see a step by step breakdown of how to set this up so I could identify where maybe I was going wrong. This has been my approach:

1.npm install --save realm

2.drag RealmReact.xcodeproj file into my ReactNativeStarter.xcodeproj and include header search paths as described above and link libRealmReact.a framework. (alternativley react-native link realm seems to have the same effect???)

3.when I build I am getting an error that 'React/RCTBridgeDelegate.h' file not found in node_modules/realm/react-native/ios/RealmReact. (I notice that the Pods/Header/ folder is completely empty)

@savelichalex

This comment has been minimized.

Copy link

commented Jun 6, 2017

Hi, I'm also trying to install realm through cocoapods. Manual linking not helping in my case, because I'm using use frameworks! in my Podfile and that mean that React using as dynamic library. That also forces me to create podspec for realm. Right now I'm have something like this in realm folder on node_modules:

# coding: utf-8
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
  s.name                    = 'RealmJS'
  s.version                 = package["version"]
  s.summary                 = package["description"]

  s.homepage                = "https://realm.io"
  s.source                  = { :git => 'https://github.com/realm/realm-js.git', :tag => "v#{s.version}", :submodules => true }
  s.author                  = { 'Realm' => 'help@realm.io' }
  s.library                 = 'c++', 'z'
  s.requires_arc            = true
  s.social_media_url        = 'https://twitter.com/realm'
  s.documentation_url       = "https://realm.io/docs/objc/#{s.version}"
  s.license                 = { :type => 'Apache 2.0', :file => 'LICENSE' }

  s.source_files            = 'react-native/ios/RealmReact/*.{h,mm}',
                              'src/*.{hpp,cpp}',
                              'src/ios/*.mm',
                              'src/jsc/*.{hpp,cpp}',
                              'src/object-store/src/*.{hpp,cpp}',
                              'src/object-store/src/sync/*.{hpp,cpp}',
                              'src/object-store/src/sync/impl/*.{hpp,cpp}',
                              'src/object-store/src/sync/impl/apple/*.{hpp,cpp}',
                              'src/object-store/src/impl/*.{hpp,cpp}',
                              'src/object-store/src/impl/apple/*.{hpp,cpp}',
                              'src/object-store/src/util/*.{hpp,cpp}',
                              'src/object-store/src/util/apple/*.{hpp,cpp}'

  s.ios.deployment_target   = '7.0'
  s.pod_target_xcconfig     = { 'APPLICATION_EXTENSION_API_ONLY' => 'YES',
                                'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14' }

  s.dependency 'React'
end

But I got this error: impl/collection_change_builder.cpp:19:10: 'impl/collection_change_builder.hpp' file not found in src/object-store/src/impl folder. Looks like that problem with linking, but really I don't know how to solve it. I'm trying add 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/RealmJS/src"' to s.pod_target_xcconfig and got Apple Mach-O Linker Error. Maybe someone know how to properly link it?

Also I want to ask, how Realm add constructor to js global namespace. I'm just walking around js codebase and found that in index.js file, Realm constructor should be defined yet.

@kristiandupont

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2017

@savelichalex

This comment has been minimized.

Copy link

commented Jun 7, 2017

@kristiandupont Sorry for stupid question, but how this code run in application? I mean, what need to do (how link this file properly) to execute this code at runtime and add constructor to js context

@kristiandupont

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2017

@savelichalex sorry, but I haven't tried building with cocoapods and we don't officially support it so I am not sure myself :-)

@savelichalex

This comment has been minimized.

Copy link

commented Jun 7, 2017

@kristiandupont I'm just trying to understand how it works and maybe this help me to understand how properly link it) I'm don't understand at which point in time jsc_init.cpp is calling and add constructor to js context. If rephrase: how initialization of library work

@conanwsz

This comment has been minimized.

Copy link

commented Jun 24, 2017

Also wish to see support Cocoapods.

@lucasleelz

This comment has been minimized.

Copy link

commented Nov 28, 2017

For iOS development, most developers use CocoaPods for dependency building.
It's like android using Gradle for building.
If a library does not provide CocoaPods or Carthage, I think it is not professional enough.
For me, on the one hand really want to use realm-js, the other side need to use CocoaPods. So, I gave up realm. I thought it was only for half a year just because time was not enough. Come back, still do not support. Very disappointed.

@allenhsu

This comment has been minimized.

Copy link

commented Feb 7, 2018

FYI, CocoaPods v1.4.0 added support for script_phase, maybe it's possible to support CocoaPods now.

@StevenMasini

This comment has been minimized.

Copy link

commented Mar 29, 2018

It became some kind of convention to use Cocoapods to integrate React-Native dependencies for iOS.
All my dependencies are using it, except Realm.

Is there any way we could move forward on this topic ?

@aksswami

This comment has been minimized.

Copy link

commented Apr 17, 2018

Any new updates on this?

@xeuus

This comment has been minimized.

Copy link

commented May 6, 2018

i have the same problem, i can't use Cocoapods and realm at the same time, any changes ?

@bmunkholm

This comment has been minimized.

Copy link
Contributor

commented Jul 12, 2018

We haven't had time to prioritise this. It would be wonderful if someone from the community would step up and help out on this one. Thanks!

@yamiscott

This comment has been minimized.

Copy link

commented Sep 12, 2018

Not that I have time to help, though I would love to:

I've recently run into a real world need for this.

Adding this to a brownfield app, but also wanting to access realm from the iOS and Android apps directly.

On Android, this is fine, no issues.

On iOS, the following cause linker (I sort of expected this) failures:

  1. Adding Realm (cocoa) via cocoapods, collision with realm. Also requires modular headers.
  2. Adding the static library along with the reactRealm library. Collisions occur.

I've basically parked this as I don't have enough resource to tackle this.

Cocoapods would solve this as the invisible dependencies of reactRealm with Realm would be fulfilled while also exposing Realm for usage within the non-RN side of the app.

@githubdoramon

This comment has been minimized.

Copy link

commented Nov 14, 2018

Is this ever going to be tackled? Anyone figured this out?

@vdlindenmark

This comment has been minimized.

Copy link

commented Feb 28, 2019

ReactNative is making cocoapods the default for iOS projects so it would be nice to see Realm also moved that way.

See this ticket for some more info from React Native: react-native-community/discussions-and-proposals#104

@vinhtnk

This comment has been minimized.

Copy link

commented Mar 27, 2019

I have a solution: copy and import file libRealmReact.a into xcode project and build success.

@maciekstosio

This comment has been minimized.

Copy link

commented May 6, 2019

Hi @vinhtnk could you please provide steps how to import realm if I have just installed RealmJS? Do I need to add Realm to pods?

@vinhtnk

This comment has been minimized.

Copy link

commented May 6, 2019

Hi @vinhtnk could you please provide steps how to import realm if I have just installed RealmJS? Do I need to add Realm to pods?

Hi @maciekstosio the following steps:

  • go to node_modules/realm/src/RealmJS.xcodeproj
  • build Realm project to libRealmJS.a
  • copy libRealmJS.a to current ios project directory
  • open current project and add the libRealmJS.a to project
  • at project target -> General -> Linked Frameworks and Libraries -> add libRealmJS.a
  • and now build successful without error
@maciekstosio

This comment has been minimized.

Copy link

commented May 6, 2019

Thanks @vinhtnk for so quick answer. I believe I have linked libRealmJS.a but I'm not sure how to import it to my native code (native function called from RN), sorry if it's obvious but I don't really have iOS experience

@vinhtnk

This comment has been minimized.

Copy link

commented May 6, 2019

Thanks @vinhtnk for so quick answer. I believe I have linked libRealmJS.a but I'm not sure how to import it to my native code (native function called from RN), sorry if it's obvious but I don't really have iOS experience

Hi @maciekstosio, the RealmJS only use for RN imported to iOS project, if you want to use realm for native also, you need to use RealmSwift or RealmCocoa. And if you want communicate between RN and native please refer RN docs: https://facebook.github.io/react-native/docs/communication-ios

@dnolbon

This comment has been minimized.

Copy link

commented Jul 2, 2019

It's seems to work only without use_frameworks! option in Podfile

@lebedev

This comment has been minimized.

Copy link

commented Jul 2, 2019

Oh, I thought this issue was about supporting Realm as a pod. I second @dnolbon. For a while I have had working app with React Native installed with CocoaPods and Realm included as a library. Without use_frameworks! option if that matters. No other setting was required.

@zek zek referenced this issue Jul 11, 2019
@dsemenov

This comment has been minimized.

Copy link

commented Jul 27, 2019

  • go to node_modules/realm/src/RealmJS.xcodeproj
  • build Realm project to libRealmJS.a
  • copy libRealmJS.a to current ios project directory
  • open current project and add the libRealmJS.a to project
  • at project target -> General -> Linked Frameworks and Libraries -> add libRealmJS.a
  • and now build successful without error

Were you able to access the same Realm file from React Native and from Swift/ObjC? Could you please show how your Podfile look like?
I'm getting the same error again and again:
.../libRealmReact.a(table.o) ld: 505 duplicate symbols for architecture x86_64

Thank you!

@corradio

This comment has been minimized.

Copy link

commented Jul 30, 2019

This is extremely helpful as we're currently unable to use realm with use_frameworks due to its inability to find React headers. We can include the React project but then we have duplicate symbols. The solution would be to only keep React inside Pods, and thus to migrate Realm to Pods as well. Is anyone working on this?

@jaysquared

This comment has been minimized.

Copy link

commented Aug 6, 2019

I slightly modified the Pods Header Search Path:
$(SRCROOT)/../../../../ios/Pods/Headers/Public/React-Core

Otherwise I would get compiler errors around time.h

I also removed GCDWebServer from here, as I have it in another dependency
RealmReact.xcodeproj/Libraries/RealmJS.xcodeproj/Vendor/GCDWebServer

Now it builds and runs without issues.

@esutton

This comment has been minimized.

Copy link

commented Aug 12, 2019

Anyone have a realm fork with a podspec supporting react native 0.60?

Out of the many react native packages my app uses, realm is the only one to NOT have a podspec yet.

Work-around:

Call this from your package.json postinstall script.

echo "Create podspec for realm"
cat > ./node_modules/realm/realm.podspec << ENDOFFILE
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
  s.name         = package['name']
  s.version      = package['version']
  s.summary      = package['description']
  s.license      = package['license']

  s.authors      = package['author']
  s.homepage     = package['homepage']
  s.platform     = :ios, "7.0"

  s.source       = { :git => "https://github.com/realm/realm-js.git", :tag => "#{s.version}" }
  s.source_files  = "ios/*.{h,m}"

  s.dependency 'React'
end
ENDOFFILE

Add this to your /ios/Podfile

  pod 'realm', :path => '../node_modules/realm'  

Never mind.

Now I have a run time error missing realm-constructor.

How can realm be used in a react native 0.60 project that is using podfiles?

2019-08-12 11:45:43.530 [error][tid:com.facebook.react.JavaScript] Missing Realm constructor. 
Did you run "react-native link realm"? 
Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
@rudyryk

This comment has been minimized.

Copy link

commented Aug 12, 2019

@esutton Seems like we need more than just s.source_files = "ios/*.{h,m}"

And btw I'm also here:

Out of the many react native packages my app uses, realm is the only one to NOT have a podspec yet.

20+ other libs but only for Realm there's no podspec.

@esutton

This comment has been minimized.

Copy link

commented Aug 12, 2019

@rudyryk I tried changing my realm.podspec to be more inclusive without success to s.source_files = "**/*.{h,m}".

Since upgrading to react native to 0.60.4, I have everything building using pods except for realm js.

@Dexwell

This comment has been minimized.

Copy link

commented Aug 19, 2019

Until this is implemented, this is how to get your project to build: #2431 (comment)

Drag RealmReact.xcodeproj to Libraries, then add both libRealmReact.a and libRealmJS.a to Linked Frameworks and Binaries.

@bmunkholm bmunkholm added the T-Doc label Sep 4, 2019
@MobileAppVault

This comment has been minimized.

Copy link

commented Sep 5, 2019

I can confirm. RN 0.60 and Realm is working with below manual steps

1. Manual linking RealmReact

Drag RealmReact.xcodeproj to Libraries, 

then add both libRealmReact.a and libRealmJS.a to Linked Frameworks and Binaries

#2431 comment

2. modify header search patch

I slightly modified the Pods Header Search Path:
$(SRCROOT)/../../../../ios/Pods/Headers/Public/React-Core

Otherwise I would get compiler errors around time.h

I also removed GCDWebServer from here, as I have it in another dependency
RealmReact.xcodeproj/Libraries/RealmJS.xcodeproj/Vendor/GCDWebServer
@OceanHorn

This comment has been minimized.

Copy link

commented Sep 6, 2019

@MobileAppVault
It works in most situations, but won't work when needing to enable use_frameworks! configuration.

@harunsmrkovic

This comment has been minimized.

Copy link

commented Sep 17, 2019

Inability to link Realm via CocoaPods (with use_frameworks!) option is what's preventing me to use it in my project... Really hope to see this resolved 🤞

@agustin107

This comment has been minimized.

Copy link

commented Sep 30, 2019

I can confirm. RN 0.60 and Realm is working with below manual steps

1. Manual linking RealmReact

Drag RealmReact.xcodeproj to Libraries, 

then add both libRealmReact.a and libRealmJS.a to Linked Frameworks and Binaries

#2431 comment

2. modify header search patch

I slightly modified the Pods Header Search Path:
$(SRCROOT)/../../../../ios/Pods/Headers/Public/React-Core

Otherwise I would get compiler errors around time.h

I also removed GCDWebServer from here, as I have it in another dependency
RealmReact.xcodeproj/Libraries/RealmJS.xcodeproj/Vendor/GCDWebServer

This works for me! Thanks @MobileAppVault

@sam-drew sam-drew referenced a pull request that will close this issue Oct 9, 2019
0 of 8 tasks complete
@kmvkrish

This comment has been minimized.

Copy link

commented Oct 13, 2019

Try adding $(SRCROOT)/../../../../Pods/Headers/Public to the "Header Search Paths" for the RealmReact target.

To do this:

  1. Select the RealmReact project in your Xcode project
  2. Select the RealmReact Target
  3. Select "Header Search Paths" under the Build Settings tab
  4. Add the above path to the list of existing search paths. The path above assumes both your Pods directory and your node_modules directory are at the top level of your project.

This Header_Search_Path is already available for RealmReact.xcodeproj. But the build is failing with <React/RCTBridge+Private.h> file not found error. This is occurring with React Native version 0.60+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.