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:
native.cpp:
#include <string.h>
#include <jni.h>
jstring Java_com_optimuse_app_OptimuseAppActivity_generate(JNIEnv* env, jobject thiz){
return env->NewStringUTF("Hello from JNI !");
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.cpp
include $(BUILD_SHARED_LIBRARY)
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.
OptimuseAppActivity.java:
package com.optimuse.app;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class OptimuseAppActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText( generate() );
setContentView(tv);
}
public native String generate();
static {
System.loadLibrary("native");
}
}
And the automatically generated AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.optimuse.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:hasCode="true">
<activity
android:name="com.optimuse.app.OptimuseAppActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for any suggestions, been searching for a few hours now!