realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.62k stars 558 forks source link

Incompatible with React Native Autolinking (React Native v0.60) #2460

Closed s1ro6 closed 4 years ago

s1ro6 commented 4 years ago

Goals

Use the Realm.js with React Native Autolinking correctly.

Expected Results

Don't show warning information.

Let the CocoaPods don't show warning after executing pod install.

Actual Results

After the pod install, it shows the following warning:

[!] use_native_modules! skipped the react-native dependency 'realm'. No podspec file was found.
    - Check to see if there is an updated version that contains the necessary podspec file
    - Contact the library maintainers or send them a PR to add a podspec. The react-native-webview podspec is a good example of a package.json driven podspec. See
    https://github.com/react-native-community/react-native-webview/blob/master/react-native-webview.podspec
    - If necessary, you can disable autolinking for the dependency and link it manually. See
    https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-disable-autolinking-for-unsupported-library

Steps to Reproduce

cd ${REACT_NATIVE_PROJECT_ROOT_PATH}
npm install --save realm
cd ios && pod install & cd ..

Version of Realm and Tooling

cantonalex commented 4 years ago

What's the workaround for this?

reyn-nova commented 4 years ago

What's the workaround for this?

run npx react-native link realm then npx jetify ignore the warning, my project is running properly with that

m-ochyra commented 4 years ago

What's the workaround for this?

run npx react-native link realm then npx jetify ignore the warning, my project is running properly with that

Jetify is for Android.

I have different issue but I think it is connected with autolinking on iOS. After realm installation, pod install gives me following error:

[!] Invalid `Podfile` file: no implicit conversion of nil into String.

 #  from /Users/marcinochyra/projects/classified/ios/Podfile:37
 #  -------------------------------------------
 #  
 >    use_native_modules!
 #  end
 #  -------------------------------------------
mnlbox commented 4 years ago

Related warning:

warn The following packages use deprecated "rnpm" config that will stop working from next release:
  - realm: https://realm.io
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
flaming-codes commented 4 years ago

To fix the pod's use_native_modules!-error, just add a react-native.config.js-file in the root of your project with the following code (exclusive example for realm, but you get the idea):

module.exports = {
  dependencies: {
    realm: {
      platforms: {
        ios: null // disable iOS platform, other platforms will still autolink if provided
      }
    }
  }
};

👉 autolinking info for more details

Disabling autolinking means we have to use good ol' manual linking, but sadly realm doesn't provide a guide here and the standard way (as told by the react-native-team) doesn't work, either.

I followed this guide, but still get the Cannot read property 'debugHosts' of undefined error. It looks like the export of NativeModules in RealmJS is undefined, thus no destruction of debugHosts.

The realm problem I see here is that realm currently doesn't use CocoaPods for iOS, which prohibits auto linking.

Looking forward for this issue being fixed.

Edit: Fix typo react-native.config.js

kangfenmao commented 4 years ago

warn The following packages use deprecated "rnpm" config that will stop working from next release:

Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.

image

edritech93 commented 4 years ago

same for me

conorbr commented 4 years ago

I'm getting the same error as @excitedcat. Has anyone found a solution?

d14na commented 4 years ago

Currently we only support React Native (both iOS & Android)

I would beg to differ. Finally upgraded to RN 0.60 (you know to support 64-bit on Play), and now I gotta go looking for an alternative local db. ugh!

liamjones commented 4 years ago

@d14na You don't need to change DB. We've got two RN 0.60.5 apps using Realm 2.29.1 live with the Android 64-bit update.

The only issue right now is that it doesn't support autolinking, but that doesn't mean you can't use the module.

Just tell RN it doesn't support autolinking on ios (Android actually works fine since it works in a different manner) by editing your react-native.config.js like so:

module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

Since you're upgrading a project I assume your iOS project already has the manually linked RealmReact.xcodeproj? That'll be sufficient for the iOS side. On the Android side ensure the implementation project(':realm') isn't in the app/build.gradle and:

include ':realm'
project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android')

isn't in the settings.gradle and you should be good to go on both platforms. Android will autolink, iOS won't.

joaodematejr commented 4 years ago

+1

blagoev commented 4 years ago

Hey everyone. There are already plans to fix this soon.

mattmogford commented 4 years ago

Really could do with Hermes at the moment so this is good news

On Wed, 4 Sep 2019, 19:40 blagoev, notifications@github.com wrote:

Hey everyone. There are already plans to fix this soon.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/realm/realm-js/issues/2460?email_source=notifications&email_token=AASPEEOMTET4QQPTUOJVDILQH76JTA5CNFSM4IFC34MKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD54R6EA#issuecomment-528031504, or mute the thread https://github.com/notifications/unsubscribe-auth/AASPEEL7Q4BXGTQLAJPRJXDQH76JTANCNFSM4IFC34MA .

mohammadalijf commented 4 years ago

can it be marked as bug? i use custom xcode config file for Develop, Stage, Release. using both Cocoapods and manual linking cause xcode fail due to incorrect CONFIGURATION_BUILD_DIR for staging configuration

imchathu87 commented 4 years ago

I m using React Native 0.60.5 for my project and I am having the same issue. I tried every thing guys suggested here and nothing happened. I added realm 2.29.1 and done react-native link command and linked the library and then added the react-native-config file and added the code suggested by one guy here to ignore pod lookup for realm. Nothing happening and I am still getting an error of 'Native Module cannot be null' Error

henriqueweiand commented 4 years ago

I have this problem too :(

Malikkhoja-zz commented 4 years ago

Facing same issue :(

ertankara commented 4 years ago

I was hyped to use RealmDB for the current project but, I've been chasing errors after errors. This is an awesome project and I really hope to see it up without errors soon :/

pengcao1 commented 4 years ago

any solution or update for react-native 0.60 above??

Yieron commented 4 years ago

What's the workaround for this?

run npx react-native link realm then npx jetify ignore the warning, my project is running properly with that

image not work

kraenhansen commented 4 years ago

I'm working on this from https://github.com/realm/realm-js/tree/kh/podspec, after checkout run pod spec lint to attempt a compilation. Any help getting this to pass linting would be greatly appreciated.

hpentimalli commented 4 years ago

I'm getting the same error as @excitedcat. Has anyone found a solution?

I've tried the solutions posted here, and manual linking works.

  1. Add a react-native.config.js config file in the root of the project with this content:
module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

That will skip autolinking for Realm for iOS.

  1. Add the project RealmReact.xcodeproj from node_modules into your project as a subproject

  2. Be sure to include libRealmReact.a in the Link Binary With Libraries step of your target Build Phases. Important: I've spent a lot of time chasing the Cannot read property 'debugHosts' of undefined bug because I was linking to libRealm.a and not libRealmReact.a, I'm sure that may happen to someone else.

kmvkrish commented 4 years ago

I'm getting the same error as @excitedcat. Has anyone found a solution?

I've tried the solutions posted here, and manual linking works.

  1. Add a react-native.config.js config file in the root of the project with this content:
module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

That will skip autolinking for Realm for iOS.

  1. Add the project RealmReact.xcodeproj from node_modules into your project as a subproject
  2. Be sure to include libRealmReact.a in the Link Binary With Libraries step of your target Build Phases. Important: I've spent a lot of time chasing the Cannot read property 'debugHosts' of undefined bug because I was linking to libRealm.a and not libRealmReact.a, I'm sure that may happen to someone else.

We have followed the same approach, but ended up with the error "React/RCTBridge+Private.h file noti found"

Can you please suggest us if we have missed specifying any PODs path in HEADER_SEARCH_PATH of the iOS project?

abcpen-inc commented 4 years ago

I'm getting the same error as @excitedcat. Has anyone found a solution?

I've tried the solutions posted here, and manual linking works.

  1. Add a react-native.config.js config file in the root of the project with this content:
module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

That will skip autolinking for Realm for iOS.

  1. Add the project RealmReact.xcodeproj from node_modules into your project as a subproject
  2. Be sure to include libRealmReact.a in the Link Binary With Libraries step of your target Build Phases. Important: I've spent a lot of time chasing the Cannot read property 'debugHosts' of undefined bug because I was linking to libRealm.a and not libRealmReact.a, I'm sure that may happen to someone else.

We have followed the same approach, but ended up with the error "React/RCTBridge+Private.h file noti found"

Can you please suggest us if we have missed specifying any PODs path in HEADER_SEARCH_PATH of the iOS project?

Add RealmReact target to Podfile,It's work,but can't Archive.

target 'RealmReact' do
  pod 'React', :path => '../node_modules/react-native/'
  project '../node_modules/realm/react-native/ios/RealmReact.xcodeproj'
end
kraenhansen commented 4 years ago

I have a PR ready for this https://github.com/realm/realm-js/pull/2586. If some of you have experience writing Podspec files and especially in the context of React Native libraries, it would be really awesome if you spent a few minutes reviewing the change and adding a comment on the PR.

It would also be great if one or more of you wanted to test out the changes:

  1. Clone the PRs branch: git clone --recurse-submodules --single-branch --branch kh/podspec https://github.com/realm/realm-js.git
  2. Pack Realm JS to an archive: npm pack
  3. From your app, install Realm JS from the archive: npm install [path to realm-js]/realm-3.3.0.tgz
  4. Install CocoaPods in your app: pod install (from your ./ios directory).
  5. Build your app and confirm that it's working .. you might need to run react-native unlink realm first.
kenbchung commented 4 years ago

@kraenhansen I tried cloning your branch as suggested and installing realm from the npm pack output, but i'm getting this error when trying to do pod install

cp: src/object-store/src/*.hpp: No such file or directory

kraenhansen commented 4 years ago

@kraenhansen I tried cloning your branch as suggested and installing realm from the npm pack output, but i'm getting this error when trying to do pod install

cp: src/object-store/src/*.hpp: No such file or directory

I pushed an update to the branch, please pull and try again. I also forgot to add the --recurse-submodules on the clone command above, please try that again too.

GreyGao commented 4 years ago

fix my question: if Podfile we used use_frameworks! then it can not be found /Pods/Headers/Public/React-Core anymore so how could I fix this problem

prscX commented 4 years ago

Hi @kraenhansen: I have tried installing realm using your branch. Post installation, I am encountered with below error during project build, as per issues/2271 I have tried adding JavaScriptCore.framework but no luck:

Screenshot 2019-11-02 at 10 02 36 PM

Could you please guide me to solve this issue.

Thanks </ Pranav >

kraenhansen commented 4 years ago

I've pushed to the kh/podspec branch what I believe is a fix for the case where the Podfile calls use_frameworks!.

@GreyGao Please pull the latest update to the branch and try again.

@prscX You are you using use_frameworks! in your Podfile, right? Please pull the latest update to the branch and try again.

prscX commented 4 years ago

Thanks a lot @kraenhansen for quick support. It worked post taking pull 💯.

Yes, I am using use_frameworks! in Podfile for few Swift library integration.

Thanks </ Pranav >

GreyGao commented 4 years ago

Thanks for @kraenhansen help!😄 ❤️ It works.

kraenhansen commented 4 years ago

Great! We'll roll-up a release with this ASAP.

cmeiller commented 4 years ago

@kraenhansen I tried your package but I got this error to run on simulator:

Undefined symbols for architecture x86_64:
  "_RCTJSThread", referenced from:
      -[RealmReact setBridge:] in RealmReact.o
  "_RCTRegisterModule", referenced from:
      +[RealmReact load] in RealmReact.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What's wrong?

kraenhansen commented 4 years ago

@cmeiller

What's wrong?

I believe this is caused by the Podspec incorrectly referencing the RCTBridge headers. Would you mind sharing a bit more information about your setup?

cmeiller commented 4 years ago

@kraenhansen yes I have the latest changes and I'm calling use_frameworks! in my Podfile. Here is my directory root structure (I cut the root files below):

Capture d’écran 2019-11-04 à 13 02 26

Thank you for your answer :)

kraenhansen commented 4 years ago

@cmeiller I've moved our conversation to a new issue https://github.com/realm/realm-js/issues/2590, let's continue there.

esutton commented 4 years ago

@CaptainQuark could you please edit your comment?

File name must be: react-native.config.js

- react-native-config.js <= Wrong !!!!
+ react-native.config.js
flaming-codes commented 4 years ago

@CaptainQuark could you please edit your comment?

File name must be: react-native.config.js

- react-native-config.js <= Wrong !!!!
+ react-native.config.js

 🤦‍♂️ Sure, fixed.

WiharlleyWill commented 1 year ago

Apply this

npm install realm@hermes

Work's for me.