Reputation: 71
I am using C++ to code in Android (I am using cocos2d-x, specifically).
Now, say, I have a class, MyClass
, with .h and .cpp files. I would like to create a .so out of these files. Then, I would like to include that .so in my project and access it via #include "MyClass.h"
. Is it possible? If so, how? Thanks!
Upvotes: 1
Views: 945
Reputation: 4205
To build your static library for ARM you can use the NDK standalone toolchain.
Once you've compiled your .so
, you can include the library in your project using the Android NDK make file (Android.mk) which will look like the following:
LOCAL_PATH := $(call my-dir)
LOCAL_SRC_FILES := my_module.so
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
You'll want to make sure you include the headers (/include) in the right path.
Not sure if your intent is to ge back into Android-land with your code, but if you're looking to create a bridge between your .so/C/C++ code and Java, you'll need to describe the appropriate JNI methods in C, build out the necessary Java classes with the static System.loadLibrary('my_module')
imports and native
method declarations mapped to your JNI methods.
Upvotes: 1