3

I have a problem when using ndk in Android

First, I have MainActivity class / A & B classes In native-lib.cpp, I implemented two functions which will be used in A / B classes as follows.

=========================================

extern "C"{
int Java_packagename_A_Afunc();
double Java_packagename_B_Bfunc();}

=========================================

Also, in both A and B classes, library is set and functions are declared as follows.

=========================================

class A:

static { System.loadLibrary("native-lib"); }
public native double A();

class B:

static { System.loadLibrary("native-lib"); }
public native double B();

=========================================

However, when I run this program, I abruptly stopped. Also, in native-lib.cpp, although I used the functions in two classes, following message is appeared when the cursor is positioned on the name of function.

=========================================

Function 'Java_packagename_A_Afunc' is never used

Function 'Java_packagename_B_Bfunc' is never used

=========================================

What's wrong in my program code?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Hiije
  • 41
  • 1
  • _"I abruptly stopped"_ And what is the error you're getting in the logs? Also, why is `A` returning an `int` in your C++ code but declared as `double` in your Java code? – Michael Nov 24 '16 at 18:21
  • Is it real C++ declarations, that you pass to compiler, or just some kind of pseudocode? – Sergio Nov 25 '16 at 11:35
  • If you are using the native library from more than one class then define your native library calls and loading the library itself in a class of their own. – WLGfx Nov 25 '16 at 11:43
  • 1
    Are you using the JNIEXPORT and JNICALL macros? You also need to have JNIEnv* and jobject parameters in your JNI functions. See this example: http://stackoverflow.com/questions/19422660/when-to-use-jniexport-and-jnicall-in-android-ndk – samgak Nov 25 '16 at 21:57
  • To. samgak, You are right. Thank you so much. – Hiije Nov 28 '16 at 13:17

0 Answers0