Hi, all
Now, I am trying to verify the JNI in Android java platform.
I am using HTC G1 phone.
I write a simple .c file to make a hello.so and a simple hello.java file to
load the library. My story is like below:
1. create hellolib.c file and compiled to a hellolib.so
create a folder in
create a hellolib.c file hellolib.c, it really nothing just a function
return;
*#include <jni.h>*
*#define .LOG_TAG "TestLib"*
*#undef LOG*
*#include <utils/Log.h>*
*JNIEXPORT void JNICALL java_com_testHelloLib_PrintHello(JNIEnv * env,
jobject jobj)*
*{*
*LOGD("hello android LIB");*
*}*
I compiled the hellolib.c to .so by changing the android.mk:
*LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)*
*LOCAL_SRC_FILES := \
hellolib.c*
*LOCAL_C_INCLUDES := \
$(JNI_H_INCLUDE)*
*LOCAL_SHARED_LIBRARIES := \
libutils
LOCAL_PRELINK_MODULE := false*
*LOCAL_MODULE := libhello *
*include $(BUILD_SHARED_LIBRARY)
*
push the libhello.so to /system/lib
2. create a .java file.
*public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
native_test.add_xx(1, 2) ;*
* }*
*
}
class native_test{
static {
System.loadLibrary("hello");// System.loadLibrary("media_jni");
}*
* public native_test(HelloAndroid helloAndroid) {
return;
}
public static int add_xx(int a, int b)
{
return 0;
}
}*
3. push the .apk to the phone and run from eclips
always a run time error like:"the application hello.android has stopped
unexpectedly, pla try again"
I changed the System.loadLibrary("hello") to a
System.loadLibrary("media_jni") like I saw in android source code, I get the
same error.
so, Could anyone help me to teach me where is my error? I missed something?
If my hellolib.so has problem, why I load the media_jni still meet the
problem? if my .java has problem, but it seems really like my java is like
the source code. Do I need to expose the .h file to java app?
I am really new for java programming, appreciate for your help!
Thanks
with best wishes
Jerry
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---