react-nativeandroid-libraryios-libraryreact-native-modules

How to create react native wrappers for native android and iOS SDKs


I am creating a React Native module as a wrapper for existing Android and iOS libraries. The Android library is a jar file and the iOS library is xcframework file. I put the xcframework file inside the ios folder, and the jar file inside android/libs folder ( I created the libs folder). I first tried the iOS library by adding s.preserve_path, s.xcconfig and s.vendored_framework inside the project level podspec file. I am not sure if I need to do anything for the pod spec file, like running it. So I just went along with the next step by trying to import the library's .h in .m file. I tried both using angle brackets <> and using quotes "". But none worked, because firing "react-native run-is" gave me this error: fatal error: file not found. Any help on how to include the libraries in react native is greatly appreciated.


Solution

  • I was able to fix the error by doing the following two steps:

    1. Change "s.vendored_framework" to "s.vendored_frameworks" in the project level .podspec file. My original one is singular (framework), not plural (frameworks).

    2. cd iOS && pod install && cd ..

    Step 2 can be found in create-react-native-module's GitHub link: https://github.com/brodybits/create-react-native-module

    I missed the second step when posting my question. I thought then that if I ran "react-native run-ios", it would run "pod install".