1

看来这是一个流行的问题,

而且我仍然没有找到解决方案。

package nameapp.cloudstringers

Java file : Completed.java

static {
    try {
        System.loadLibrary("ffmpeg");
    } catch (UnsatisfiedLinkError e) {
        Log.d("", "Error : " + e.toString());
    }

}

    // Define native method
public native int getString();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page_completed);

    // Call native method
    Log.d("", "" + getString());

C++ file : ffmpeg.cpp

#include <jni.h>
#include <android/log.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jstring JNICALL Java_app_cloudstringers_Completed_getString(JNIEnv* env, jobject thiz)
{
jstring strRet = env->NewStringUTF("HelloWorld from JNI !");
return strRet;
}

#ifdef __cplusplus
}
#endif

Android.mk file

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := ffmpeg
LOCAL_SRC_FILES := ffmpeg.cpp
include $(BUILD_SHARED_LIBRARY)

我运行应用程序但仍然收到错误异常UnsatisfiedLinkError : getString

知道如何解决这个问题的人,

请告诉我,

谢谢

更新 关注@dextor 的回答。对不起,因为我弄错了。对于这个问题,我唯一需要的就是从 更改public native int getString()public native String getString()

现在可以了。

4

1 回答 1

2

不确定(实际上没有尝试过),但我注意到的唯一错误是您的方法声明的返回类型。

Java端

public native int getString()

NDK端

JNIEXPORT jstring JNICALL Java_app_cloudstringers_Completed_getString(JNIEnv* env, jobject thiz)

在 Java 中,您有一个int. 在 C 端,您有一个jstring.

于 2014-03-24T14:00:01.840 回答