我正在尝试将libbmp
库作为共享库移植到Android
。我的Android
项目在jni
文件夹下包含以下内容:
Android.mk(热门Android makefile
)
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
libbmp
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libbmp
LOCAL_SRC_FILES := bmpfile.c
include $(BUILD_SHARED_LIBRARY)`
bmpfile.c(从libbmp-0.1.3中提取)
libbmptest
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := PortingShared
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../libbmp/
LOCAL_SRC_FILES := PortingShared.c
LOCAL_SHARED_LIBRARIES := libbmp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)`
PortingShared.c(利用libbmp
函数中的naCreateABmp
库)
#include <jni.h>
#ifndef _Included_cookbook_chapter8_portingshared_MainActivity
#define _Included_cookbook_chapter8_portingshared_MainActivity
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: cookbook_chapter8_portingshared_MainActivity
* Method: naCreateABmp
* Signature: (III)V
*/
JNIEXPORT void JNICALL Java_cookbook_chapter8_portingshared_MainActivity_naCreateABmp
(JNIEnv *env, jclass clazz, jint width, jint height, jint depth);
bmpfile_t *bmp;
int i, j;
rgb_pixel_t pixel = {128, 64, 0, 0};
for (i = 10, j = 10; j < height; ++i, ++j) {
bmp_set_pixel(bmp, i, j, pixel);
pixel.red++;
pixel.green++;
pixel.blue++;
bmp_set_pixel(bmp, i + 1, j, pixel);
bmp_set_pixel(bmp, i, j + 1, pixel);
}
bmp_save(bmp, "/sdcard/test_shared.bmp");
bmp_destroy(bmp);
#ifdef __cplusplus
}
#endif
#endif
我还必须提到我的MainActivity.java
正在加载libbmp
和PortingShared
库以及调用native
函数naCreateABMP
public static native void naCreateABmp(int width, int height, int depth);
static {
System.loadLibrary("bmp");
System.loadLibrary("PortingShared");
}
但是,当我尝试使用ndk-build
命令构建它时,我得到错误:
PortingShared/jni/libbmptest/PortingShared.c:18:1: error: unknown type name 'bmpfile_t'
PortingShared/jni/libbmptest/PortingShared.c:20:1: error: unknown type name 'rgb_pixel_t'
PortingShared/jni/libbmptest/PortingShared.c:20:1: warning: excess elements in scalar initializer [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:20:1: warning: (near initialization for 'pixel') [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:20:1: warning: excess elements in scalar initializer [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:20:1: warning: (near initialization for 'pixel') [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:20:1: warning: excess elements in scalar initializer [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:20:1: warning: (near initialization for 'pixel') [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:22:1: error: expected identifier or '(' before 'for'
PortingShared/jni/libbmptest/PortingShared.c:22:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
PortingShared/jni/libbmptest/PortingShared.c:22:34: error: expected identifier or '(' before '++' token
PortingShared/jni/libbmptest/PortingShared.c:31:15: error: expected ')' before string constant
PortingShared/jni/libbmptest/PortingShared.c:32:1: warning: data definition has no type or storage class [enabled by default]
PortingShared/jni/libbmptest/PortingShared.c:32:1: warning: parameter names (without types) in function declaration [enabled by default]
make: *** [PortingShared/obj/local/armeabi/objs/PortingShared/PortingShared.o] Error 1