嗨,Ivgot 设置了 gnu make buldier Cros GCC,以及由 cygwin 创建的 javah,. hedaer 文件。我在同一个 jni 目录中有 .h 和 .cpp:我不明白这个错误:
make all
Building file: ../jni/com_jp_algi_CoreC.cpp
Invoking: Cross G++ Compiler
g++ -I"C:\android-ndk-r5c\platforms\android-9\arch-arm\usr\include" -O0 -g3 - Wall -c -fmessage-length=0 -MMD -MP -MF"jni/com_jp_algi_CoreC.d" - MT"jni/com_jp_algi_CoreC.d" -o "jni/com_jp_algi_CoreC.o" "../jni/com_jp_algi_CoreC.cpp"
../jni/com_jp_algi_CoreC.cpp:2:31: fatal error: com_jp_algi_CoreC.h: No such file or directory
jni/subdir.mk:18: recipe for target `jni/com_jp_algi_CoreC.o' failed
compilation terminated.
make: *** [jni/com_jp_algi_CoreC.o] Error 1
Android buldier 可以工作,但是 ...Syas 这个错误没有实现 ....antive。我必须使用我的外部制作,当我在cygwin中通过javah创建.h时......也许我将这个java项目转换为C++ - 添加性质..也许会有问题?
我得到了这个.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := com_jp_algi_CoreC
LOCAL_SRC_FILES := com_jp_algi_CoreC.cpp
include $(BUILD_SHARED_LIBRARY)
.cpp:
#include <com_jp_algi_CoreC.h>
/* Header for class com_jp_algi_CoreC */
extern "C" {
JNIEXPORT void JNICALL Java_com_jp_algi_CoreC_vector
(JNIEnv *env, jobject clazz, jfloatArray input){
jfloat* flt1=NULL ;
jsize size = env->GetArrayLength(input);
jint i;
// check if array size >0 and wedont cause exception
// allocate buffer for array and get data from Java array
flt1 = new jfloat[size];
env->GetFloatArrayRegion(input,0,size,flt1);
// exception check. Always use exception check
// do stuff to the array
for (i = 0 ; i < size; i++){
flt1[i] = 1;
}
// vector(flt1);
// set result to Java array and delete buffer. And exception check of course
env->SetFloatArrayRegion(input,0,size,flt1);
delete[] flt1;
// All is ok
}
JNIEXPORT void JNICALL Java_com_jp_algi_CoreC_vector2
(JNIEnv *, jobject, jfloatArray, jobjectArray);
}
.h: /* 请勿编辑此文件 - 它是机器生成的/#include / com_jp_algi_CoreC 类的标头 */
#ifndef _Included_com_jp_algi_CoreC
#define _Included_com_jp_algi_CoreC
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_jp_algi_CoreC
* Method: vector
* Signature: ([F)V
*/
JNIEXPORT void JNICALL Java_com_jp_algi_CoreC_vector
(JNIEnv *, jobject, jfloatArray);
/*
* Class: com_jp_algi_CoreC
* Method: vector2
* Signature: ([F[[F)V
*/
JNIEXPORT void JNICALL Java_com_jp_algi_CoreC_vector2
(JNIEnv *, jobject, jfloatArray, jobjectArray);
#ifdef __cplusplus
}
#endif
#endif
这个 CoreC 类:
package com.jp.algi;
public class CoreC {
static {
System.loadLibrary("com_jp_algi_CoreC");
}
public native void vector(float[] input);
public native void vector2(float[] input, float[][] input2);
}