库到Android端口

时间:2014-09-05 16:09:21

标签: java android c++ android-ndk shared-libraries

我正在尝试将libbmp库作为共享库移植到Android。我的Android项目在jni文件夹下包含以下内容:

  1. Android.mk(热门Android makefile

    LOCAL_PATH := $(call my-dir)
    include $(call all-subdir-makefiles)
    
  2. 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中提取)

    • bmpfile.h(从libbmp-0.1.3中提取)
  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
      
  4. 我还必须提到我的MainActivity.java正在加载libbmpPortingShared库以及调用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
    

0 个答案:

没有答案