I am trying to run an easy Android ndk app in cpp, but I get UnsatisfiedLink Error for the Generate() function.

Any help would be appreciated. I am quite fluent in c++, but my java is a little bit rusty. I have been trying a lot of tips from the web concerning naming, but so far no luck. Here are my files:


#include <string.h>
#include <jni.h>

jstring Java_com_optimuse_app_OptimuseAppActivity_generate(JNIEnv* env, jobject thiz){
    return env->NewStringUTF("Hello from JNI !");


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := native
LOCAL_SRC_FILES := native.cpp


I compile this with ndk-build and all goes well, it provides me with a libnative.so, that is located in the project directory. I use eclipse for the rest.


package com.optimuse.app;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class OptimuseAppActivity extends Activity 
    public void onCreate(Bundle savedInstanceState)
        TextView  tv = new TextView(this);
        tv.setText( generate() );

    public native String generate();

    static {

And the automatically generated AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

        android:label="@string/app_name" android:hasCode="true">
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />


Thank you for any suggestions, been searching for a few hours now!

The cpp syntax was a bit different from the c you see everywhere...

extern "C" {
JNIEXPORT jstring JNICALL Java_com_optimuse_app_OptimuseAppActivity_generate(JNIEnv* env, jobject thiz){
    return env->NewStringUTF("Hello from JNI cpp!");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.