I am trying to port the libbmp library to Android as a shared library. My Android project contains under the jni folder the following:
Android.mk (top
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 (extracted from libbmp-0.1.3)
- bmpfile.h (extracted from 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 (makes use of the
libbmplibrary innaCreateABmpfunction)#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
I must also mention that my MainActivity.java is loading the libbmp and PortingShared libraries as well as calling the native function naCreateABMP
public static native void naCreateABmp(int width, int height, int depth);
static {
System.loadLibrary("bmp");
System.loadLibrary("PortingShared");
}
However, when I try to build it with the ndk-build command, I get the errors:
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