Re-use code Android NDK

孤人 提交于 2019-12-18 17:58:42

问题


I found a lot of tutorials showing how to start developing Android Applications using NDK.

But I have a rather "easy/stupid" question:

Please consider the following two tutorials:

  1. http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/
  2. http://www.indiedb.com/tutorials/creating-compiling-and-deploying-native-projects-from-the-android-ndk
  3. http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/
  4. http://marakana.com/forums/android/examples/49.html

Now, in the second tutorial they are building the hello-jni example.

My question is:

After using the ndk-build

and producting the:

is it possible to use the resulted libhello-jni.so and distribute this to others instead of the actual C code?

For example modifying the Android.mk and replacing com_myproject_MyActivity.c to something.so in order to include the 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 tutorials welcome. Thanks in advance.


回答1:


You can use a prebuilt NDK library by copying it into libs/armeabi (or whatever architecture is it for), then loading in run-time. From the standpoint of the Android build system, it's just another file to include in the APK.

The problem, however, is that the JNI function names include, by convention, the name of the package and class they will belong to; so from the standpoint of a SO consumer project, its use will look rather unnatural, as none of the JNI functions would fit into its classes. You'll probably have to ship a companion JAR where the respective Java classes are declared.




回答2:


Via VitamioBundle,

You no need to do re-using code:

is it possible to use the resulted libhello-jni.so and distribute this to others instead of the actual C code? For example modifying the Android.mk and replacing com_myproject_MyActivity.c to something.so in order to include the 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 considered as shared library,

Therefore, you can use it as your Android Library.

Let's fun.



来源:https://stackoverflow.com/questions/12195426/re-use-code-android-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!