ios-jsc: Metadata found but symbol not available at runtime

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 5.1.0
  • Cross-platform modules: 5.1.2
  • iOS Runtime: 5.1.0

Describe the bug

I am trying to implement a custom plugin for NativeScript using libsodium (https://github.com/jedisct1/libsodium). I have downloaded source files & complied to generate libsodium.a & header files. After that I put in my plugin following “https://docs.nativescript.org/plugins/plugin-reference”. It’s generating typescript definition correctly but when I am trying to use in demo app like this:

console.dir(crypto_aead_aes256gcm_abytes())

But getting errors like this:

 file:///app/main-view-model.js:8:49: JS ERROR ReferenceError: Metadata for "sodium.crypto_aead_aes256gcm_abytes" found but symbol not available at runtime.
    (CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: ReferenceError: Metadata for "sodium.crypto_aead_aes256gcm_abytes" found but symbol not available at runtime.

Architectures:

lipo -info sodium.a    
Architectures in the fat file: sodium.a are: i386 armv7 armv7s x86_64 arm64

In where I am doing mistake? Please give me suggestions.

To Reproduce Download latest release from here: https://github.com/jedisct1/libsodium/releases or clone the git repo. It has supplied a building script under dist-build named ios.sh to build static library for iOS.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

Upgrading tns-core-modules from 6.1.1 to 6.1.2 solved the problem.

Hey guys, my plugin nativescript-bottom-navigation stop working in NS6.

I’m getting this error ERROR ReferenceError: Metadata for "MaterialComponents.MDCBottomNavigationBar" found but symbol not available at runtime.

any ideas?

@jibon57 I’m glad you managed to make it work! Closing this issue as after the implementation of https://github.com/NativeScript/nativescript-cli/issues/4157, plugins will be able to define their own lists of exported symbols and the workaround to manually specify the options and lists in applications will no longer be required.

If you really want to keep everything you may continue with the other approach by manually removing all symbols which are reported as unavailable or hidden by the linker. It might work out in the end.

Thanks @mbektchiev . I am doing so now. This is solving my problem temporary 😃 because I don’t need all functions.

Well, it seems that this isn’t going to lead us anywhere… I would suggest that initially you find and add only the functions that you know you will call from JavaScript. You can find their mangled names in the list and include only them in the file with exported symbols. The linker will automatically leave any other symbols that may be needed by them.

The reason that these functions are missing at runtime is that the linker by default strips any unused C++ symbols. Since you call the functions from JS, the compiler and linker cannot detect that they are actually needed and remove them from the final executable. We’ve planned to add support for specifying an exported symbols file in NativeScript plugins, but currently, there isn’t such out of the box. You may try to add an EXPORTED_SYMBOLS_FILE setting in your {N} project’s build.xcconfig and list there all symbols that you need to be able to call. To retrieve a list of the mangled names of all symbols defined in the library you can use: nm --defined-only libsodium.a.

** UPDATE ** You will most probably need to specify STRIPFLAGS=$(inherited) -s <exported-symbols-file> along with EXPORTED_SYMBOLS_FILE=<exported-symbols-file>