brodycj / create-react-native-module

MIT License
666 stars 52 forks source link

Not Able to make it work in iOS for react native 0.61.5 #245

Open kashifaliquazi opened 4 years ago

kashifaliquazi commented 4 years ago

I am trying to integrate this Module in my react Native App with version 0.61.5.

Here is what I am trying to achieve:

I want to create a Module with Some Native Code for React Native application which can be directly called from React Native JS.

Here is what I have done so far.

1.) Installed create-react-native-module Globally. 2.) Created a Module inside node_modules with "create-react-native-module " command. 3.) run npm install inside react-native-my-module folder created by above (2) command.

Now I am trying to call "sampleMethod" of MyModule.m file from app.js(of react native).

I have tried calling it with


import MyModule from 'react-native-my-module'; MyModule.sampleMethod();

but give me Error as soon as I try to import MyModule from 'react-native-my-module': "Invariant violation: Module HMRClient is not a registered callable module(calling setup)"


import { NativeModules } from 'react-native';

const { MyModule } = NativeModules; MyModule.sampleMethod();

but it gives me error as soon as I call sampleMethod: TypeError: null is not an object(evaluating 'MyModule.sampleMethod')


I also Tried linking the Module manually by: 1.) Adding MyModule.xcodeproj file in librery. 2.)adding libMyModule.a in buid Phase (link binary with librery)

After Manual Linking project build is getting failed with error: "fatal error: 'React/RCTBridgeModule.h' file not found"


I am not sure what is the correct or recommended way of doing it. Any Help would be appreciable. Thanks,

brodycj commented 4 years ago

I had trouble using the example module with npm install, would highly recommend you consider using Yarn instead.

I have undergone quite a bit of testing efforts to hopefully ensure that this tool will generate a library module with an example app already working from the beginning.

In case of continued issues please post the command you used to generate the app and post a repository on GitHub with a minimal, reproducible example ([1]).

[1] https://stackoverflow.com/help/minimal-reproducible-example

cmcaboy commented 4 years ago

@brodybits I was also able to reproduce the issue. I literally just upgraded the cli to the latest version and created a new module. Trying to build the app on ios either through xcode or react-native run-ios both resulted in the same error:

image

Here is the command I ran to generate the project:

create-react-native-module testModule

Here is a minimal, reproducible example: https://github.com/cmcaboy/react-native-test-module

I am on version 0.14.0: image

I hope this helps!

cmcaboy commented 4 years ago

This may be an another issue, but your completion prompt references an example, but there isn't an example directory in the generated module:

image

image

cmcaboy commented 4 years ago

Hmm, I guess it would have helped to look at the cli options.

create-react-native-module --generate-example testModule

After running this and building the project from the example from the module itself, everything seemed to build/compile.

TommyLeong commented 4 years ago

@cmcaboy Everything seemed to build/compile? do you mean the ExampleProject itself or the TestModule itself?

I did the same by running create-react-native-module --generate-example testModule

brodycj commented 4 years ago

You just build and run the example project.

For the sake of extra clarity, I will go through it. From your command:

create-react-native-module --generate-example testModule

you would do cd into react-native-test-module/example and then do react-native run-ios from that example subdirectory.

  • ExampleProject build successfully,

yes

  • TestModule still complains for 'React/RCTBridgeModule.h' file not found`

That case is not tested or supported by myself. Some other people have worked on this for Android and maybe for iOS, but I have not been actively testing or supporting this case.

TommyLeong commented 4 years ago

Thanks for the prompt response. I have tried to build a few dependency lib in my project with Xcode, all the project does not get successful build. I guess we don't need to have them build successfully? 😕

Since it works fine in the exampleProject, I guess we are all good. 🤞

cmcaboy commented 4 years ago

Yeah, I was confused as well. I thought we needed to be able to build and compile the actual library rather than the example. Once I figured out that I had to build/compile from the example, everything made sense.

@brodybits Do you think we should update the documentation to explain this? I can submit a PR if needed.

brodycj commented 4 years ago

@brodybits Do you think we should update the documentation to explain this?

yes

I can submit a PR if needed.

A contribution would definitely be appreciated, thanks.

eurobob commented 4 years ago

I would disagree that this issue is fine since it builds in the example.

I am also facing this issue. I followed the usage instructions perfectly, several times. But I can't get the same result in my actual project

anand-hsc commented 4 years ago

I agree with @eurobob: Library should be built independently and let me tell the reason. Say I have to make a patch in the already published module by someone else, so I m not the owner of that module and it does not contain any example project. So in this case how we will proceed, we need to create an example project first inside that module (not aware of how we can do this)and then test it? or use from any demo RN application and add as folder dependency using command yarn add filename/foldername. Both ways it is very difficult. Require suggestion !!