问题
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:
- http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/
- http://www.indiedb.com/tutorials/creating-compiling-and-deploying-native-projects-from-the-android-ndk
- http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/
- 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