JNI (easy?) question: java.lang.UnsatisfiedLinkError

I am quite a newbie with JNI and get the following issue:

I added the following method to the class Cocos2dxRenderer.java:

 public void handleBuyCoins0(){
        nativeBuyCoins0();
   }

I get the following error when trying to execute “nativeBuyCoins0();”

03-24 01:18:43.685: E/AndroidRuntime(3612): FATAL EXCEPTION: GLThread 10
03-24 01:18:43.685: E/AndroidRuntime(3612): java.lang.UnsatisfiedLinkError: nativeBuyCoins0
03-24 01:18:43.685: E/AndroidRuntime(3612):     at org.cocos2dx.lib.Cocos2dxRenderer.nativeBuyCoins0(Native Method)
03-24 01:18:43.685: E/AndroidRuntime(3612):     at org.cocos2dx.lib.Cocos2dxRenderer.handleBuyCoins0(Cocos2dxRenderer.java:106)
03-24 01:18:43.685: E/AndroidRuntime(3612):     at org.cocos2dx.lib.Cocos2dxGLSurfaceView$4.run(Cocos2dxGLSurfaceView.java:227)
03-24 01:18:43.685: E/AndroidRuntime(3612):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1346)
03-24 01:18:43.685: E/AndroidRuntime(3612):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)

The nativeBuyCoins0() method is not found.

This method is in one of the .cpp classes of my project. Here is the code:

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeBuyCoins0()
{
    CCLog("Entered void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeBuyCoins0() !!"); 
}

I clearly miss something in order to allow my Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeBuyCoins0() to be found. But what ?

Thanks for your help

Hello,
I also have encountered this error.
I followed this tutorial http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_use_jni (with the same functions and variables)

in my src folder, in the package org.cocos2dx.lib in the class Cocos2dxActivity

    ...
    private native int nativeAdd(int a, int b);

    public void setLocalizacionLanguage() {
         int sum = this.nativeAdd(1, 2);
    }
    ...

And in my C*+ project, in a random class in the .cpp i have
<pre>

#include “android\jni\JniHelper.h”

jint Java_org_cocos2dx_lib_Cocos2dxActivity_nativeAdd
{
return a* b;
}

I compile the c++ project without problems (i’m putting all JNI related code between \#if (CC\_TARGET\_PLATFORM == CC\_PLATFORM\_ANDROID) ) but when I compile and execute in java it crashes with :
 W/dalvikvm(4264): No implementation found for native Lorg/cocos2dx/lib/Cocos2dxActivity;.nativeAdd (II)I
 W/dalvikvm(4264): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
 E/AndroidRuntime(4264): FATAL EXCEPTION: main
 E/AndroidRuntime(4264): java.lang.UnsatisfiedLinkError: nativeAdd
 E/AndroidRuntime(4264):    at org.cocos2dx.lib.Cocos2dxActivity.nativeAdd(Native Method)
 E/AndroidRuntime(4264):    at org.cocos2dx.lib.Cocos2dxActivity.setLocalizacionLanguage(Cocos2dxActivity.java:143)
 E/AndroidRuntime(4264):    at com.games.fvz.twice.FVZ_2_1.onCreate(FVZ_2_1.java:34)
 E/AndroidRuntime(4264):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
 E/AndroidRuntime(4264):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
 E/AndroidRuntime(4264):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
 E/AndroidRuntime(4264):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
 E/AndroidRuntime(4264):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
 E/AndroidRuntime(4264):    at android.os.Handler.dispatchMessage(Handler.java:99)
 E/AndroidRuntime(4264):    at android.os.Looper.loop(Looper.java:123)
 E/AndroidRuntime(4264):    at android.app.ActivityThread.main(ActivityThread.java:4627)
 E/AndroidRuntime(4264):    at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(4264):    at java.lang.reflect.Method.invoke(Method.java:521)
 E/AndroidRuntime(4264):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
 E/AndroidRuntime(4264):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 E/AndroidRuntime(4264):    at dalvik.system.NativeStart.main(Native Method)

so, i’m completely lost. I do not understand if i should create a class for the functions, declare them in another place or what is happening.
If you could help i would be truly happy

Thank you

OK, i know what i’m doing wrong, although i don’t completely understand how this works, i can’t just put the C*+ function in any class, it has to be “linked” to the java project. In my case, it’s “main.cpp” when i change my c*+ function in there, i can find it without problems.

thanks and sorry!

i met the same problem do you solve it ?
chuel chuelin wrote:

OK, i know what i’m doing wrong, although i don’t completely understand how this works, i can’t just put the C*+ function in any class, it has to be “linked” to the java project. In my case, it’s “main.cpp” when i change my c*+ function in there, i can find it without problems.
>
thanks and sorry!