Search code examples
iosnativescriptnativescript-plugin

Creating NativeScript Plugin using iOS SDK results in 'Undefined symbols for architecture' errors


I am trying to create a NativeScript plugin in order to integrate an iOS SDK of a bluetooth printer to a NativeScript application.

Here is the link to the SDK as Static Framework

I keep getting the following error with the army7 part showing different values after fresh install of the plugin.

Undefined symbols for architecture armv7:
  "_CBCentralManagerScanOptionAllowDuplicatesKey", referenced from:
      -[RTBleService startScan:serviceArray:clear:] in RTPrinterSDK(RTBleService.o)
  "_OBJC_CLASS_$_CBCentralManager", referenced from:
      objc-class-ref in RTPrinterSDK(RTBleService.o)
  "_OBJC_CLASS_$_CBUUID", referenced from:
      objc-class-ref in RTPrinterSDK(RTBleService.o)
ld: symbol(s) not found for architecture armv7
note: Using new build systemnote: Planning buildnote: Constructing build description

In addition to trying to use the official plugin seed plugin, I have ultimately done the following which according to my research should have been enough:

INSTALLATION:

1) Created a folder for the plugin files within the /app directory (this plugin is only intended for this project at present). This folder has the following structure:

/app/plugin/src/package.json   
/app/plugin/src/platforms/ios/RTPrinterSDK.framework  

The RTPrinterSDK.framework has two folders, Headers (has .h files) and Modules (has the module.modulemap file) in addition to two files being Info.plist and RTPrinterSDK.a.

2) I have added the plugin to the project by running tns plugin add app/plugin/src

3) I believe now tns run ios --bundle should run the project on the connected device with the plugin - albeit I have not done anything with the plugin yet on the application.

SANITY CHECKS:

1) lipo -info app/plugin/src/platforms/ios/RTPrinterSDK.framework/RTPrinterSDK displays that the Architectures in the fat file: /path-to-RTPrinterSDK are: army7 i386 x64_64 arm64.

2) tns run ios --bundle without the custom plugin works both in emulators and real device

3) just in case, I have also attempted this on a fresh new --ts project

4) there is a demo application that comes with the SDK. Whilst it is not a NativeScript application, it is an Xcode project file and I was able to successfully run it on the same connected device.

There is a note in the SDK referring to a ble_serial.plist file. As per the instructions, I am confident that I need to integrate this to somewhere within the plugin folder to access bluetooth connectivity but I am not sure where. Given that the errors are referring to modules with "Ble" in the name, I fear there might be a connection.

Please note that I did not write/prepare the SDK. The vendor of the printer provided it. I only have access to it as it is provided.

I would hugely appreciate any tips or feedback regarding this issue.


Solution

  • Following valuable advice from the NativeScript community, I discovered that the CB prefix in the errors refer to CoreBluetooth.

    In order to ensure that it is loaded I ended up creating a new file at /app/plugin/src/platforms/ios/build.xcconfig and adding the following line to it:

    OTHER_LDFLAGS = $(inherited) -framework "CoreBluetooth".

    It compiles and runs on device now.