Android NDK Reuse Code

I found many tutorials that show how to start developing Android applications using the NDK.

But I have a pretty "easy / dumb" question:

Please review the following two guides:

Now in the second tutorial they create an example of hello-jni .

My question is:

After using ndk-build

and produce:

enter image description here

Is it possible to use the provided libhello-jni.so and extend this to other, rather than the actual C code?

For example, changing Android.mk and replacing com_myproject_MyActivity.c with something.so to include a shared library ?:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := mylib LOCAL_SRC_FILES := com_myproject_MyActivity.c include $(BUILD_SHARED_LIBRARY) 

Any suggestions or manuals are appreciated. Thanks in advance.

+3
source share
2 answers

You can use the pre-created NDK library by copying it to libs/armeabi (or any other architecture) and then loading it at runtime. In terms of the Android build system, this is just another file to be included in the APK.

However, the problem is that JNI function names include, by convention, the name of the package and the class to which they will belong; therefore, from the point of view of the SO consumer project, its use will look rather unnatural, since none of the JNI functions will fit into its classes. You may have to send a JAR satellite where the corresponding Java classes are declared.

+3
source

Via VitamioBundle ,

You do not need to reuse the code:

Is it possible to use the provided libhello-jni.so and extend this to others, and not to the actual code? For example, changing Android.mk and replacing com_myproject_MyActivity.c with something. To enable a shared library?

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := mylib LOCAL_SRC_FILES := com_myproject_MyActivity.c include $(BUILD_SHARED_LIBRARY) 

VitamioBundle can be thought of as a shared library,

Therefore, you can use it as your Android library.

Let fun.

0
source

Source: https://habr.com/ru/post/916912/


All Articles