Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot call native method eclipse

I am developing an android app using C++ code. Trying using JNI but failed. here is my code: from test.c in jni folder:

jstring Segment_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz )
{
    return (*env)->NewStringUTF(env, "test");
}

I already build by ndk and generate libtest.so. but in my BrowsePicture.java (under Segment.com.example.segment) I added

public native String  test();

But I couldn't call it. the message is :

E/AndroidRuntime(16748): java.lang.UnsatisfiedLinkError: Native method not found: com.example.segment.BrowsePicture.test:()Ljava/lang/String;

So can anyone tell me what's wrong?

like image 532
Le Duy Khanh Avatar asked Jul 18 '26 14:07

Le Duy Khanh


2 Answers

try with change method name by this...

jstring Java_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz )

instead of this...

jstring Segment_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz )
like image 111
Priyank Patel Avatar answered Jul 21 '26 02:07

Priyank Patel


Have you declared another class like the one below

package com.yourpackage;
public class NativeLib {

static {
    System.loadLibrary("yourlibrary");
}

public static native void your_function(your_arguments);
}

Then call this function from your activity using

NativeLib.your_function(your_arguments);
like image 20
Royston Pinto Avatar answered Jul 21 '26 04:07

Royston Pinto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!