I have a java project and now I want to add some NDK functionality.
here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android
LOCAL_CFLAGS := -Wno-psabi
LOCAL_SRC_FILES := android.c
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
here is my android.c
#include <jni.h>
#include <string.h>
#include <android/log.h>
#define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"
void Java_ru_tonybo_app_NativeRenderer_print(JNIEnv* env, jobject thiz, jstring message) {
jboolean isCopy;
const char * szMessage = (*env)->GetStringUTFChars(env, message, &isCopy);
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szMessage);
(*env)->ReleaseStringUTFChars(env, message, szMessage);
}
here is my related java class
package ru.tonybo.app;
public class NativeRenderer {
public NativeRenderer (String message) {
print(message);
}
public native void print(String message);
static {
System.loadLibrary("android");
}
}
NDK compilation through cygwin is ok
TonyBo@TonyBo-NoteBook /cygdrive/d/javaProjects/App_JNI/jni
$ /cygdrive/d/android-ndk-r8b/ndk-build -B
Cygwin : Generating dependency file converter script
Compile thumb : android <= android.c
SharedLibrary : libandroid.so
Install : libandroid.so => libs/armeabi/libandroid.so
libandroid.so is created and placed in /libs/armeabi/libandroid.so
but when I launch the application in eclipse on the device, I got the exception UnsatisfiedLinkError on native call print(message);
What I’m missing here or doing wrong?
May be I should somehow tell eclipse to look for shared libraries, if so how to do this?
Your choice of libandroid name is not a good idea. The library libandroid.so exists in the system folder /system/lib. It is loaded into your app, and therefore your
Load()call simply returns. If you change the name of your native library, everything will be well.