2014年2月8日 星期六

[NDK] Dynamic loading share library .so 動態連接.so檔

假設libndk.so要動態連接(dynamic loading) libandroid.so

 1/ manually place libandroid.so into $PROJECT_PATH/libs/armeabi
 2/ create a new NDK shared library which source code uses "dlopen()" to load libandroid.so at runtime
 3/ create an Android.mk that uses LOCAL_LDLIBS += -ldl (ensures you can use dlopen)
 4/ build your libndk.so with the NDK build script
 5/ rebuild your apk from Eclipse or Ant, the resulting .apk should have both libraries under lib/armeabi/

2014年2月7日 星期五

[NDK] JNI log in android NDK

add in android.mk file
LOCAL_LDLIBS += -llog

add in your .c file
#include <android/log.h>
#define LOG_TAG "System.out"

#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)



Now you can show your log info in this .c file
LOGD("%s","hahahaha1");