Using a static iOS library in a NativeScript 5.4 plugin - ios

NativeScript 5.4.2
tns-core-modules 5.4.3
tns-ios 5.4.2
Xcode 10.2.1
I am attempting to create a plugin for this background geolocation library for iOS: https://github.com/Yermo/background-geolocation-ios
The project produces a static library, libBackgroundGeolocation.a.
I have read the documentation on how to use a static iOS library: https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#static-libraries
I have read about the required directory structure: https://docs.nativescript.org/plugins/plugin-reference#directory-structure
My plugin is based on the official plugin seed, so I have a demo directory and a src directory containing my plugin code and a platforms/ios directory under that.
I have copied the BackgroundGeolocation.a file into src/platforms/ios.
I have created a src/platforms/ios/include/BackgroundGeolocation directory and copied the public header files from the project into that directory.
I notice that src/platforms/ios/include/BackgroundGeolocation/module.modulemap file has been created.
In the plugin directory I can successfully run 'npm run build'.
However, from the demo directory if I run 'tns build ios' I consistently get a "ld: Library not found for -lBackgroundGeolocation" error.
If I rename the library to libBackgroundGeolocation.a I get the "ENOENT: no such file or directory, scandir '.....ios/include/libBackgroundGeolocation" so I surmise it's at least recognizing that the library is there.
I thought that maybe it was a path problem so I tried setting the library include path explicitly in build.xcconfig using the full path to the platforms/ios directory.
No joy. It still doesn't find the library but if I misspell the name of the directory in the -L in build.xcconfig it flags a directory not found error.
I then thought that maybe it had to do with the targets in the library so I followed the recipe here Build fat static library (device + simulator) using Xcode and SDK 4+ to include multiple targets.
Still no joy.
I suspect I am missing something fundamental.
What am I doing wrong?
Is there a working recent working sample somewhere of how to wrap a static iOS library as a NativeScript plugin?

It turns out adding
LIBRARY_SEARCH_PATHS = $(inherited) "$(SRCROOT)/../../node_modules/<projectname>/platforms/ios
to the src/platforms/ios/build.xcconfig file resolved this issue.

Related

Using Xcode project in react native plugin causes header file not found errors

I'm developing a react native plugin (iOS) that uses another project as depencency. Building the project on its own, no errors occur. When I build a react native app with my plugin inside, I get the error that some header files are not found in my plugin.
My structure
MyReactNativeApp
node_modules
myPlugin
iOS
myPlugin.xcodeproj
folder1
myProject1.xcodeproj
folder2
myProject2.xcodeproj
folder3
file1.h
folder4
file2.h
myProject2 has some header files defined that reference to each other.
When I build myProject1.xcodeproj, there are no errors. When I build myPlugin, the header files can't include each other.
The header search paths are set. This shouldn't be the problem.
Does someone may has an idea what could be the reason?
I didn't find a solution for this problem, but one for my actual problem that .framework modules couldn't be found. Due to this error I tried to add the project directly.
If a .framework module could not be found, you need to add this to your .podspec file of myPlugin
s.vendored_frameworks = 'ios/Frameworks/myProject1.framework', 'ios/Frameworks/myProject2.framework'
s.public_header_files = 'ios/Frameworks/myProject1.framework/**/*.h'
Maybe only the s.public_header_files will fix the error in the question.

Module 'Swift' was created for incompatible target x86_64-apple-ios13.0

I'm creating an iOS framework and I want to copy some Xcode templates from my framework directory (that are not included in my .xcproject, but are in the folder that contains the project), when my framework is installed trought Cocoapods. In other words, when a developer installs my framework with Cocoapods or manually, I want to copy the templates into his Xcode Template Files folder.
I'm trying to execute a swift script file from the build phase of Xcode like this:
swift "${SRCROOT}/Folder/Folder/installer.swift"
But I get this error when I try to build it:
/<unknown>:1:1: module 'Swift' was created for incompatible target x86_64-apple-ios13.0: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule
If I execute swift installer.swift from the terminal, the script works. So, I think there is a problem with my Xcode.
My installer.swift file copies the template files to the Xcode Template Files folder.
I don't know if this way is the correct one, but I didn't find any other solution so far.
When I tried something similar I had to tell swift to compile for macOS by adding the following "shebang" comment as the first line of the swift script:
#!/usr/bin/env xcrun --sdk macosx swift

React native iOS library not found after updating

After I update an already existing React Native library, should i relink it again?.
ld: library not found for -lBranch-SDK
in addition,when I run react-native-link I get
react-native-branch ERR! Failed to add file to project
linking just sets up your native projects to link to the module in your node_modules. Unless there is a major change to the module, you only need to do it once.
For iOS, this will modify your .pbxproj file, updating your targets and adding links to the framework (if needed) and the .xcodeproj in node_modules/<module>
For android, it will modify your settings.gradle file to include the project from node_modules. It will also update your build.gradle to compile the new library, and it will modify your MainApplication.java file to add the new lib to react.

Flutter Plugin Development native vendored_frameworks file not found

I'm working on the flutter-webrtc plugin for iOS. Previously, the plugin use the prebuilt cocoapods dependency. But, in the WebRTC M80 Release Notes they state they are going to be deprecating the mobile libraries.
To stay up to date with the latest iOS native WebRTC bugfixes and features, we now need to build from source.
I've built from source and I was testing it with WebRTC's AppRTCMobile example app and it is working over there. Now I am trying to import the WebRTC.framework into the flutter plugin and I'm having trouble.
There is no flutter documentation on this, but I followed guidance from this github issue. I've copied the binary built from source into the plugin ios directory and modified the flutter_webrtc.podspec to include the framework, but I'm getting the error:
Xcode's output:
↳
In file included from /Users/corey/Workspace/flutter/flutter-webrtc/ios/Classes/FlutterWebRTCPlugin.m:1:
/Users/corey/Workspace/flutter/flutter-webrtc/ios/Classes/FlutterWebRTCPlugin.h:4:9: fatal error: 'WebRTC/RTCDataChannel.h' file not found
#import <WebRTC/RTCDataChannel.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from /Users/corey/Workspace/flutter/flutter-webrtc/ios/Classes/FlutterRTCVideoRenderer.m:1:
In file included from /Users/corey/Workspace/flutter/flutter-webrtc/ios/Classes/FlutterRTCVideoRenderer.h:1:
/Users/corey/Workspace/flutter/flutter-webrtc/ios/Classes/FlutterWebRTCPlugin.h:4:9: fatal error: 'WebRTC/RTCDataChannel.h' file not found
#import <WebRTC/RTCDataChannel.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Planning build
note: Constructing build description
I'm really new to flutter plugin development so I'm not sure if I'm doing this correctly. Any tips would be very appreciated!
After adding the binary to the plugin ios directory, I needed to manually go into my app's ios directory (the app depending on the plugin) and manually run pod install && pod update.
After that, the plugin import errors were fixed and I'm now using WebRTC built from source in the flutter-webrtc plugin :)

Facebook iOS SDK 3.1 from Github missing FacebookSDK.framework

I want to use Facebook SDK on XCode 4.5 for integration with iOS6.
I read this tutorial. I was using this .dmg package to install the library but I need to track and read the implementation of some methods, so I noticed that there is a repo on Github with the current source code.
My problem is that I don't know how to install this properly as with the package .dmg. Any ideas on how to do it? I tried to just import the src folder and reference the whole project but I'm having a lot of issues, warnings and errors.
Update
I had to do this again, so now I made it work. Here is what I did:
I tried both ways, building the source code (1) and importing the files directly(2). On the first scenario it was easy, on the root folder of Github repo just run:
sudo scripts/build_framework.sh
You will get the files needed, the same that you get when installing with .pkg. But I needed to track the functions, so I tried to importing the files.
First I added the src folders from the Github repo on my project. I had an issue with duplicated definitions on every file. The problem was on my Build Settings (BS), I was still referencing to the .pkg install directory of Facebook so I had the files duplicated. I removed every reference to that folder on BS and then added the files.
After that, on the files that imported the Facebook files I got:
Undefined symbols for architecture i386
When I copied the files to XCode, the .m files where not automatically added to the Build Phases / Compile Sources. I added them manually and imported FBConnect.h on my files.
Hope it helps some one with the same issue.
If you include the FacebookSDK via git, you will need to build the framework. Run the following command from within the FacebookSDK directory:
scripts/build_framework.sh
Then, FacebookSDK.framework will appear in FacebookSDK/build
Add the entire src folder to your project. Import FBConnect.h in any class where you want to use Facebook. The connect class imports the rest of the necessary classes.
#import "FBConnect.h"

Resources