add some codes,like this:
------------------------------
static JNINativeMethod FileBrowseMethods[] = {
                {"OpenStream", "(Ljava/lang/String;)V",
(void*)Java_yuan_tang_fu_FileBrowse_OpenStream },
        };
        
        static const char *FileBrowseClassName = "yuan/tang/fu/FileBrowse";

        static int registerNativeMethods(JNIEnv* env, const char* className,
                                                                         
JNINativeMethod* gMethods, int numMethods)
        {
                jclass clazz;
                //fprintf(stderr, "RegisterNatives start for '%s'", className);
                
__android_log_print(ANDROID_LOG_ERROR,"registerNativeMethods","RegisterNatives
start for '%s'", className);
                clazz = env->FindClass(className);
                if (clazz == NULL) {
                        //fprintf(stderr, "Native registration unable to find 
class '%s'",
className);
                        
__android_log_print(ANDROID_LOG_ERROR,"registerNativeMethods",
"Native registration unable to find class '%s'", className);
                        return JNI_FALSE;
                }
                if (env->RegisterNatives(clazz, gMethods, numMethods)<0) {
                        //fprintf(stderr, "RegisterNatives failed for '%s'", 
className);
                        
__android_log_print(ANDROID_LOG_ERROR,"registerNativeMethods",
"RegisterNatives failed for '%s'", className);
                        return JNI_FALSE;
                }
                return JNI_TRUE;
        }
static int registerNatives(JNIEnv* env)
        {
                if (!registerNativeMethods(env, FileBrowseClassName,
                                                                   
FileBrowseMethods, sizeof(FileBrowseMethods) /
sizeof(FileBrowseMethods[0]))) {
                        // return JNI_FALSE;
                }
        
                
                return JNI_TRUE;
        }
        typedef union {
                JNIEnv* env;
                void* venv;
        } UnionJNIEnvToVoid;
        jint JNI_OnLoad(JavaVM* vm, void* reserved)
        {
                UnionJNIEnvToVoid uenv;
                uenv.venv = NULL;
                jint result = -1;
                JNIEnv* env = NULL;
                //printf("JNI_OnLoad");
                        __android_log_print(ANDROID_LOG_ERROR,"JNI_OnLoad", 
"JNI_OnLoad...");
                if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) {
                        //fprintf(stderr, "GetEnv failed");
                        __android_log_print(ANDROID_LOG_ERROR,"JNI_OnLoad", 
"GetEnv failed");
                        goto bail;
                }
                env = uenv.env;
                if (registerNatives(env) != JNI_TRUE) {
                        //fprintf(stderr, "GetEnv failed");
                        __android_log_print(ANDROID_LOG_ERROR,"JNI_OnLoad",
"registerNatives failed");
                        goto bail;
                }
        result = JNI_VERSION_1_4;
        bail:
                return result;
        }


2010/12/22 TobyKaos <aubrun.thib...@chaos-interactive.com>:
> Hello, I first run samples found in androind ndk and I create my own
> in C. I successfully print a hello world with c function.
>
> but now I want to call c++ function. Then I change file extensions
> to .cpp and remake with ndk-build. Ok that seems to work fine. I
> refresh my eclispe project. Ok eclispe seems to find my hello world
> function in new .so lib made in c++.
>
> Then I launched debug and application failed because it does not find c
> ++ function. My function is the same but I modify jni function in it
> to match c++ jni.
>
> My TestSTL.java
>
> package com.project.teststl;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.TextView;
>
> public class TestSTL extends Activity {
>    /** Called when the activity is first created. */
>   �...@override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        //setContentView(R.layout.main);
>
>        TextView  tv = new TextView(this);
>        tv.setText( stringFromJNI() );
>        setContentView(tv);
>    }
>
>    native public static String stringFromJNI();
>
>    static {
>                //System.loadLibrary("stlport_shared");
>            System.loadLibrary("teststl");
>        }
>
> }
>
> *************************************
> my test.cpp file
>
> #include <string.h>
> #include <jni.h>
>
> #include <stdlib.h>
> #include <stdio.h>
>
> /* Call to initialize the graphics state */
> JNIEXPORT jstring JNICALL
> Java_com_project_teststl_TestSTL_stringFromJNI(  JNIEnv* env, jobject
> obj  )
> {
>        jstring s = (env)->NewStringUTF( "Hello from JNI !");
>
>        return s;
>
> }
>
>
>
> I repeat, in C all is ok (I just modify NewStringUTF for C or C++
> because are not the same definition).
>
> Please help me.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to