Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include custom native code in a NativeScript app?

I'm using NativeScript as the UI/mobile access layer for an app. For now, the app will only be run by me on an Android device, so cross-platform support isn't an issue. The core of the app is implemented as a Rust shared library with a JNI interface, and my primary goal is ease of development/iteration as I refine this code.

I'd like to write my Java JNI interface code directly in my NativeScript app--that is, compile the code alongside the platform-specific Java, without writing it in a separate library that gets pulled in. But it seems like the platform-specific code is auto-generated and not meant to be user-modified.

Is it possible to easily copy a few hand-written Java classes into my final NativeScript app, while using NS for the mobile interface layer? Are hooks something that could help with this?

Thanks for any pointers.

like image 469
Nolan Avatar asked Feb 12 '19 16:02

Nolan


People also ask

Is NativeScript really Native?

It allows devs to use XML, CSS, and JavaScript to build Android, iOS, and even the Universal Windows Platform applications. Unlike Cordova, which uses a WebView to render the app's UI, NativeScript uses the native platform rendering engine, which means it provides a truly native user experience.

Is NativeScript good for app development?

NativeScript makes cross-platform mobile app development easy, fast, and efficient. We are a consulting company and use NativeScript for apps internally and externally for customers.


1 Answers

With NativeScript 5.2.0 release, you are now able to add native code for both Android and iOS in your application. For Android, you can place your Java classes in <path to project's App_Resources dir>/Android/src/main/java. For iOS you can place your Objective-C implemenation in <path to project's App_Resources dir>/iOS/src directory. Here's an example application that demonstrates how to add native source code directly in your app and call it from JavaScript: https://github.com/rosen-vladimirov/appNativeCode

like image 72
Vladimirov Avatar answered Nov 09 '22 03:11

Vladimirov