Comments (12)
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
Several notes:
- This is the exact same set up I am using for my actual project
- 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
- 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
- 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.
- 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.
- 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
- Sample app: https://github.com/Travisrockgit/sample-rn-app
- Sample Library: https://github.com/Travisrockgit/rn-sample-lib
Steps to install the library (The current sample app already has library installed):
- Clone the sample app
- Navigate to root
- 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
- 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.
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.
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.
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.
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.
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.
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.
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.
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.
-
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
-
create object files for arm64 architecture for use in real devices
gcc -c addvec.c -o addvec-arm64.o -target arm64-apple-ios
-
create universal object files
lipo -create addvec-x86_64.o addvec-arm64.o -output addvec.o
-
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.
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.
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.
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
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.
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)
- Counter not showing HOT 3
- Fresh setup yields Xcode 12.4 build error: "ld: library not found for -lRNModuleTemplateModule" HOT 3
- How to use library that requires native setup? HOT 9
- Error finding the headers HOT 6
- I want to add custom fonts to the module HOT 1
- How can i add placeholder images? HOT 2
- Assets folder is not included HOT 1
- Error: Invalid Hook Call HOT 11
- Question: How to add custom styles into the library? HOT 2
- Unable to resolve module ./index HOT 2
- React Navigation error within the library HOT 2
- Renaming module template causes module to return as null in JS (Android) HOT 1
- Suggestion for Seeing Changes immediately HOT 1
- How to add custom fonts
- How to upgrade?
- Error building example app HOT 3
- How to upgrade?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-module-template.