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

Closed
afces1 opened this issue Feb 23, 2017 · 43 comments
Closed

Support React Native installed with CocoaPods #884

afces1 opened this issue Feb 23, 2017 · 43 comments
Labels
First-Good-Issue First Good Issue - Relatively easy issue for new contributers O-Community T-Bug T-Doc

Comments

@afces1
Copy link

afces1 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'

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

  2. pod install to install Yoga and React Native

  3. add RealmReact project into XCode from ../rn/node_modules/realm/react-native/ios/RealmReact.xcodeproj

  4. compile iOS app

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

@makeitnew
Copy link

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.

@karagraysen
Copy link

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
Copy link
Member

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
Copy link

natwales 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
Copy link

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
Copy link
Contributor

Realm constructor is added here: https://github.com/realm/realm-js/blob/master/src/jsc/jsc_init.cpp#L40

@savelichalex
Copy link

@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
Copy link
Contributor

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

@savelichalex
Copy link

@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
Copy link

Also wish to see support Cocoapods.

@lucaslz2020
Copy link

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
Copy link

allenhsu commented Feb 7, 2018

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

@StevenMasini
Copy link

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
Copy link

Any new updates on this?

@arianito
Copy link

arianito commented May 6, 2018

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

@maciekstosio
Copy link

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
Copy link

vinhtnk 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
Copy link

dnolbon commented Jul 2, 2019

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

@lebedev
Copy link

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

@d-sandman
Copy link

  • 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
Copy link

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
Copy link

jaysquared 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
Copy link

esutton 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
Copy link

rudyryk 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
Copy link

esutton 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
Copy link

Dexwell 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
Copy link

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
Copy link

OceanHorn commented Sep 6, 2019

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

@harunsmrkovic
Copy link

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
Copy link

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

@kmvkrish
Copy link

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+

@kneth
Copy link
Contributor

kneth commented Nov 20, 2019

In Realm JavaScript v3.4.0 we have added support for CocoaPods.

@theminerymike
Copy link

@kneth That's great to hear, but if I understand this issue properly (which I'm currently still stuck on), wouldn't we need a podspec for RealmReact as well? I'm having issues building RealmReact, not RealmJS.

@kraenhansen
Copy link
Member

kraenhansen commented Nov 21, 2019

@theminerymike - it could probably be separated into its own Subspec, but currently the RealmJS Podspec builds both Realm JS (the former libRealmJS) and Realm React into a single library.

I were the one fixing this issue and to be honest, this was my first Podspec. Any feedback on it would be greatly appreciated. Do you see an issue in compiling everything to a single library instead of separating it into Realm JS and Realm React?

@theminerymike
Copy link

Oh cool, that should do the trick. I wasn't aware of that. What I've done so far is adding this line to my Podfile, and unlinked the two realm libraries in Xcode, like I've done with other projects that now use cocoapods.

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

It seems to fail for me on line 21 of object-store/src/index_set.cpp

Screen Shot 2019-11-23 at 8 35 09 PM

realm/util/assert.hpp not found

Any advice?

@kraenhansen
Copy link
Member

kraenhansen commented Nov 24, 2019

Any advice?

@theminerymike I suspect your Podfile needs some adjustments: In general it should not need to reference RealmJS explicitly. You could have a look at the Podfile of a newly initialized React Native project. If that doesn't work, please create a new issue and posting your Podfile there.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
First-Good-Issue First Good Issue - Relatively easy issue for new contributers O-Community T-Bug T-Doc
Projects
None yet
Development

Successfully merging a pull request may close this issue.