Giter Club home page Giter Club logo

Comments (12)

Travisrockgit avatar Travisrockgit commented on September 2, 2024 1

Hi,

As discussed, I created a sample react native app (very much plain react-native init...) and a sample lib using your template.

I compiled a static library (.a) from a c file. Inside of the c file, it has one function "addVec()" that adds 2 vectors together. I then added that .a file along with header to iOS part of the sample app. In native swift, I have a function called "test()" which uses "addVec()" function and returns the second number of the resulting vector. This "test()" function is then exported to JS side of the library for consumption. In short, app can import "RNSampleLibModule" from the library and then call the "test()" by "RNSampleLibModule.test()"

I tried to run this set up and it gives me the same error I have been having

Screen Shot 2021-11-19 at 12 02 59 PM

Screen Shot 2021-11-19 at 12 03 06 PM

Several notes:

  1. This is the exact same set up I am using for my actual project
  2. This set up (linking .a file and .h to iOS part of the project) works fine when the app consuming it, is the example app that comes from your template. No error, everything linked fine
  3. When using the set up, after "npm install git+https://github.com/Travisrockgit/rn-sample-lib#0.0.2", android side works very well. No errors
  4. The error itself may seem to suggest the architecture of the library is of the issue, but again, when linked with the same library in the example app that comes with the template, everything works fine.
  5. I have looked into your README on how the example app is linked and try to see if I could find anything that I am not working right, so far no luck.
  6. My guess: since android side works fine (meaning the library installed fine), it leads me to think that during the react native auto linking and/or pod install, the header and the .a library are not linked correctly.

Below are the path to 2 sample projects

  1. Sample app: https://github.com/Travisrockgit/sample-rn-app
  2. Sample Library: https://github.com/Travisrockgit/rn-sample-lib

Steps to install the library (The current sample app already has library installed):

  1. Clone the sample app
  2. Navigate to root
  3. Run command "npm install git+https://github.com/Travisrockgit/rn-sample-lib#0.0.2" -> '0.0.2' is the tag number, I use this to increment version
  4. The sample library will be under node_modules and ready to use

Thanks again for your time and please let me know if you need more information.

from react-native-module-template.

Travisrockgit avatar Travisrockgit commented on September 2, 2024 1

Of course! Thanks for your work on this template, definitely helps a lot. Have a good thanksgiving and stay safe.

from react-native-module-template.

demchenkoalex avatar demchenkoalex commented on September 2, 2024

Hi!

Hmm, I haven't used this kind of setup. Is this possible to find this lib or something similar so I can try to link it on my side, so I can suggest something?

from react-native-module-template.

Travisrockgit avatar Travisrockgit commented on September 2, 2024

Hi!

Thanks much for replying. Unfortunately, this library is proprietary so I cannot show the src code directly. But why don't I make a sample skeleton of what I am trying to do here and share the repo with you if it works?

In the mean time, just curious, I understand that a sample app is paired with this library template for the convenience of testing, other than publishing it to NPM for sharing, how else can I add and install this library? I have been using "npm install git+ ${REPO_PATH} ", and it has been working well. It basically grabs the code from a GitHub or bitbucket repo. This is where I am having the issues on iOS.

Note: I did use this method (npm install git+ ...) to install the library and android works fine! So my guess is that, between react native auto linking and pod install, the header file of the c code and .so file were not linked/built correctly.

Thanks again for your time.

from react-native-module-template.

demchenkoalex avatar demchenkoalex commented on September 2, 2024

Yes, the example project is just for the testing/development purposes, to see the results of the work while doing the library. It has no other applications and it is never distributed.

I never installed this library the way you do, just because I always used sample (example project) app to verify that the library works and then I just upload it to NPM. Later it is usual yarn add, nothing fancy, no pulling from GitHub.

from react-native-module-template.

demchenkoalex avatar demchenkoalex commented on September 2, 2024

Timeboxed this for an hour (I was creating a new library from scratch following your steps) but .a you've build does not contain arm64 arch and I am on Apple Silicon only. So I was trying to create my .a library, but because I have never done that spent way too much time figuring out how to do that. I can try to check it once more next week, if you will be able to give me .a for arm64 :)

from react-native-module-template.

demchenkoalex avatar demchenkoalex commented on September 2, 2024

From what I noticed though, your library exports addvec function (and in the headers everywhere it is addvec) but from Swift you call addVec (notice capital V) of course it can't found it :) just call addvec

from react-native-module-template.

Travisrockgit avatar Travisrockgit commented on September 2, 2024

Hi Alex,

Good catch on the addVec issue, sorry for the mistake there, tried to do it too fast and accidentally made a typo. I have corrected the function in the original C file, the header file, as well as the swift file that is calling it to "addVec()". I am also attaching the screenshot of the original c file here.
Screen Shot 2021-11-22 at 10 25 51 AM

After correcting those issues, I tried to build again and got the same error, "undefined symbol".

For the architecture of the static library, it should be good for both arm64-ios (assuming you have an iPhone?) and x86_64 simulator (for intel based Mac simulator).

Below are the exact steps I took to make the static library, again, I can confirm that this works for both iOS and Android when using the template example app that you have already set up ("manual link" per your documentation). And it also works on android when I tried to install the library via "npm install git+..."method. Only iOS does not like it.

  1. create object files for x86_64 architecture for use in the simulator

gcc -c addvec.c -o addvec-x86_64.o -target x86_64-apple-ios-simulator

  1. create object files for arm64 architecture for use in real devices

gcc -c addvec.c -o addvec-arm64.o -target arm64-apple-ios

  1. create universal object files

lipo -create addvec-x86_64.o addvec-arm64.o -output addvec.o

  1. create universal static library

libtool -static addvec.o -o libmathvec.a

I have updated the library tag to 0.0.4 for the rebuilt of library and the latest commit on sample app repo. The .a file in sample library is the latest rebuilt of the above steps, supporting (x86_64 Mac simulator and arm64 iOS real device).

Please let me know if I can provide anything else. And once again I appreciate your time. I am still looking into it in the mean time, I am just trying to see if I am missing anything about your template that is causing this issue. I am not sure how "hacky" it is to install private library this way but I know it works.

Thanks much!

from react-native-module-template.

demchenkoalex avatar demchenkoalex commented on September 2, 2024

Oh, I used arm64 simulator :) but I can try with an iPhone, sure, but don't know if during the week, pretty tough one on a regular job.

from react-native-module-template.

Travisrockgit avatar Travisrockgit commented on September 2, 2024

Ah I see, I THINK you can use "arm64-apple-ios-simulator" as the gcc target then for arm64 based simulator on Mac when building.

Yeah it is pretty messy when trying to link a c to swift, and then bridge it over to RN. Messier to set it up on Android though :) . I am guessing I am just missing something on Xcode to cause that c header to .a not linking right... very weird.

Sounds good about it, Thanks a lot for trying to help! I will let you know if I can get it resolved beforehand.

from react-native-module-template.

Travisrockgit avatar Travisrockgit commented on September 2, 2024

Hey I got it worked out. And kinda as expected, it is a config issue. In the LIB_NAME.podspec file, I needed to specify
Screen Shot 2021-11-23 at 2 51 00 PM

Which tells the module where the vendor library is during linking. But yeah, one liner, got me stuck for a bit.

Once again thanks for your time spent on this and trying to help!

from react-native-module-template.

demchenkoalex avatar demchenkoalex commented on September 2, 2024

Oh man, yeah that does make sense. Should've think about it sooner too. Thanks for letting me know!

from react-native-module-template.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.