的UnsatisfiedLinkError调用C在C ++从Java文件file ++方法时, [英] UnsatisfiedLinkError when calling C++ method in C++ file from Java file
问题描述
这看起来是流行的问题,
It looks like it is the popular problem,
和我还没有找到解决办法。
And I still not find out the solution.
包的名称
: app.cloudstringers
的Java文件: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 ++文件: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文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := ffmpeg.cpp
include $(BUILD_SHARED_LIBRARY)
我运行的应用程序,但仍然得到错误的异常的UnsatisfiedLinkError:的getString
人谁知道如何解决这个问题,
People who know the how to fix this problem,
请告诉我,
感谢
更新
按照@dextor答案。很抱歉,因为我得到的错误。我唯一需要的这个问题是改变从公共本地INT的getString()
到公共本地字符串的getString()
。
UPDATE
Follow @dextor answer. Sorry because I get the mistake. Only thing I need for this question is change from public native int getString()
to public native String getString()
.
它的工作原理吧。
推荐答案
不知道(实际上并没有尝试),但唯一错误的事情,我注意到的是你的方法声明的返回类型。
Not sure (didn't actually try), but the only wrong thing I've noticed is the return type of your method declarations.
Java端
公共本地INT的getString()
NDK端
JNIEXPORT的jstring JNICALL Java_app_cloudstringers_Completed_getString(JNIEnv的* ENV,jobject THIZ)
在Java中,你有一个 INT
。在C面,你有一个的jstring
。
In Java, you have an int
. On the C-side, you have a jstring
.
这篇关于的UnsatisfiedLinkError调用C在C ++从Java文件file ++方法时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!