我用javah自动创建.h文件。并依次创建.c文件。但是eclipse仍然让我找不到原生方法和类似的东西
Native method not found: com.iiordanov.bVNC.NativeCalls.getPortAndPassword:(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/Str
java文件:
package com.iiordanov.bVNC;
import java.io.IOException;
public class NativeCalls {
static
{
System.loadLibrary("start-spice-xml");
}
public native static String[] getPortAndPassword(String server, String name) throws IOException;
}
.h文件(来自extern C,它写入语法错误)
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_iiordanov_bVNC_NativeCalls */
#ifndef _Included_com_iiordanov_bVNC_NativeCalls
#define _Included_com_iiordanov_bVNC_NativeCalls
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_iiordanov_bVNC_NativeCalls
* Method: getPortAndPassword
* Signature: (Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword
(JNIEnv *, jclass, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif
.c文件(在JNIEXPORT之前尝试使用和不使用extern“C”)
#include <jni.h>
#include <android/log.h>
#include <stdio.h>
#include <com_iiordanov_bVNC_NativeCalls.h>
char *create_request(char *vm_name);
JNIEXPORT jobjectArray JNICALL Java_com_iiordanov_bVNC_NativeCalls_getPortAndPassword
(JNIEnv * env, jclass myClass, jstring nameString, jstring serverString)
...
看了几个帖子 - 他们都说我应该添加外部C - 但它没有帮助((
logcat的
03-14 19:32:09.809: E/AndroidRuntime(1157): java.lang.UnsatisfiedLinkError: Native method not found: com.iiordanov.bVNC.NativeCalls.getPortAndPassword:(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;
Android.mk文件:
include $(CLEAR_VARS)
LOCAL_MODULE := start-spice-xml
LOCAL_SRC_FILES := $(call all-c-files-under,libxml2)
include $(BUILD_SHARED_LIBRARY)
这里我刚刚添加了我的文件start-spice.c,并为NativeCalls.java生成了libxml2 .c和.h的头文件。