Hi,Kozak and all I checked the logcat, I find it cannot find the jni_Onload, Thanks for your information, I find I forget the function jni_Onload method, it is a new requirement after jni)1.2 Now my hello world working. Thanks With best wishes Jerry
On Mon, Feb 23, 2009 at 12:51 AM, kozak <c.a.subraman...@gmail.com> wrote: > > Hi, > Can you please post the logcat as well? Meanwhile, I have tried to > document something that might be similar to what you are looking for > http://mybbventures.blogspot.com/. > > BR > Kozak > > On Feb 23, 11:35 am, Jerry Yang <1999bige...@gmail.com> wrote: > > 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 > > > --~--~---------~--~----~------------~-------~--~----~ unsubscribe: android-porting+unsubscr...@googlegroups.com website: http://groups.google.com/group/android-porting -~----------~----~----~----~------~----~------~--~---