Android-runtime: import C code into {N} - clarification requested

Created on 21 Sep 2016  路  2Comments  路  Source: NativeScript/android-runtime

Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?

All my searches pointed me to this repository.

Tell us about the problem

I'm trying to add in some C code that I've generated using MATLAB Coder into my {N} app. I've looked at https://github.com/NativeScript/android-runtime/issues/291 and it gave me a bit of sense as to how to load an .so file that I should generate using Gradle. That's all fine, but it seems that the example in the sample-native-module uses C++ code (whereas I am suing C code), which is a bit different from various examples I've seen for adding C code into Android apps:
https://youtu.be/DWnadVCwMJw?t=2306
https://www.youtube.com/watch?v=G0vL7-_xuDM

Notably, I understood that I need to implement a method NSMain which would be called by {N} when I run var myModule = require('./libMyModule.so');.

The structure of NSMain is different than it seems in the other examples I viewed.

Since I was unable to find adequate examples or guides for this matter, I was hoping to get some example or clarification on how to implement NSMain and call on the exports object from V8 in order to successfully add my C functions for use in {N}.

Please provide the following version numbers that your issue occurs with:

  • CLI - 2.3.0
  • Cross-platform modules - 2.3.0
  • tns-android - 2.1.1

Thanks in advance.

Most helpful comment

@NirLevanon I managed to import this app(https://github.com/CrazyOrr/FFmpegRecorder) into aar library and call it from my {N} Application. It uses javacpp.

Here is my implementation. currently working.

  • project I trying to create aar is this. (https://github.com/matart15/FFmpegRecorder) It is working wihtout problem as application. (https://github.com/matart15/FFmpegRecorder/tree/rnu_as_application)
  • project I trying to use that aar is this (https://github.com/matart15/FFmpegRecorder_loader)

some errors happened during the development
(https://github.com/CrazyOrr/FFmpegRecorder/issues/5#issuecomment-254101072)
(https://github.com/NativeScript/android-runtime/issues/584)

All 2 comments

Hi @NirLevanon,
If you want to generate C code that can be used with NativeScript, first you'll need to build a .so library.

  • You can use make or any other build system to generate that shared library. You can look at our example here of how you can build such a library with make.
  • After you built the .so file you can simply put it in with the rest of your javascript code in <app_name>/app/ folder and require it from javascript.

@NirLevanon I managed to import this app(https://github.com/CrazyOrr/FFmpegRecorder) into aar library and call it from my {N} Application. It uses javacpp.

Here is my implementation. currently working.

  • project I trying to create aar is this. (https://github.com/matart15/FFmpegRecorder) It is working wihtout problem as application. (https://github.com/matart15/FFmpegRecorder/tree/rnu_as_application)
  • project I trying to use that aar is this (https://github.com/matart15/FFmpegRecorder_loader)

some errors happened during the development
(https://github.com/CrazyOrr/FFmpegRecorder/issues/5#issuecomment-254101072)
(https://github.com/NativeScript/android-runtime/issues/584)

Was this page helpful?
0 / 5 - 0 ratings