up9cloud / ios-libtdjson

Prebuilt [TDLib](https://github.com/tdlib/td) shared lib (libtdjson.dylib) for iOS and macOS
MIT License
6 stars 2 forks source link

Linking the library with a React-Native module #1

Open gaithoben opened 3 years ago

gaithoben commented 3 years ago

Thank you so much for the good job of compiling the library making it very easy to use in a project.

I have struggling with an issue the last three days.

I am building react-native module to consume in a react-native project using https://github.com/brodybits/create-react-native-module

Am not sure if am placing the "include" directory in the right place.

am getting the error when i import lbtdjson in a .swift file.

: error: no such module 'libtdjson'

Your help will be highly appreciated.

up9cloud commented 3 years ago

Hi, I wonder you didn't create the module_map file for swift. Please check this: https://github.com/up9cloud/ios-libtdjson#use-it-as-module-ios-swift

gaithoben commented 3 years ago

Thank you so much for your reply.

Actually i did, and it works well when i use it directly in my react-native application.

But when i try to extract it on an npm module that i can easily install, Im stuck. I really dont know what am doing wrong.

/Users/bernardgaitho/tests/cJamboTest2/node_modules/react-native-tdx/ios/TdJsonClient.swift:10:8: error: no such module 'libtdjson' import libtdjson

up9cloud commented 3 years ago

Well, I guess it's the same thing. after you installed the pod, you need to create the module file and configure it for swift. I don't think "create-react-native-module" will do it for you. Did you check the pod folder which create-react-native-module installed for your project?

up9cloud commented 3 years ago

I meant the create-react-native-module is actually doing installing pod and wrapping. You have to check the pod folder they installed for you.

gaithoben commented 3 years ago

In my example project, https://github.com/gaithoben/react-native-tdx.git, i have adjusted the .podpecs file so that the library is installed in the projects 'ios/Pods/libtdjson' folder.

I guess configuring at the module is whats giving me a headache.

gaithoben commented 3 years ago

Your help will be highly appreciated.

up9cloud commented 3 years ago

In my example project, https://github.com/gaithoben/react-native-tdx.git, i have adjusted the .podpecs file so that the library is installed in the projects 'ios/Pods/libtdjson' folder.

I guess configuring at the module is whats giving me a headache.

I think there are 2 ways to solve this:

  1. to figure out why -l"tdjson" -fmodule-map-file="${PODS_ROOT}/Headers/Public/libtdjson/libtdjson.modulemap" didn't work as expectation. (have to check the .xcconfig)
  2. download the libs and build it as a xcframework then manually add it to your lib in xcode (you might want to try https://github.com/leoMehlig/TDJSON/releases/tag/v1.6.1 )
gaithoben commented 3 years ago

Thank you for your reply. Let me test your suggestion and i will keep trying and researching...

I have never built a native project in native swift or objective c, i guess thats the reason why i find it difficult. It was not difficult to make it work in android. But to be honest this is not easy for me in iOS, if you can spare sometime and make a working example package for react-native, i will be ready to facilitate that. My email is gaithoben \at \gmail .com.

Thanks in advance.