5
votes

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.

1
I don't think you can include Java files directly, but you can convert the Java files into a JAR / AAR and place it in your App_Resources/Android/lib then the classes should be accessible at runtime. - Manoj

1 Answers

9
votes

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