我從android的源碼中提取了getevent.c getevent.h放在一個目錄下, 進行jni編譯測試
加了個Android.mkcctv5在線直播內容如下
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GetEvent
LOCAL_SRC_FILES := getevent.c
include $(BUILD_SHARED_LIBRARY)
進入源碼目錄,手動編譯:
ndk-build V=1 2>&1 | tee log.txt
查看log.txt
編譯會出現一大堆錯誤:
/opt/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -MMD -MP -MF ./obj/local/armeabi/objs/GetEvent/getevent.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Ijni -DANDROID -Wa,--noexecstack -Wformat -I/opt/android-ndk-r10d/platforms/android-3/arch-arm/usr/include -c jni/getevent.c -o ./obj/local/armeabi/objs/GetEvent/getevent.o
In file included from jni/getevent.c:14:0:
jni/getevent.h:12:15: error: 'INPUT_PROP_POINTER' undeclared here (not in a function)
LABEL(INPUT_PROP_POINTER),
^
jni/getevent.h:8:38: note: in definition of macro 'LABEL'
#define LABEL(constant) { #constant, constant }
^
jni/getevent.h:13:15: error: 'INPUT_PROP_DIRECT' undeclared here (not in a function)
LABEL(INPUT_PROP_DIRECT),
^
jni/getevent.h:8:38: note: in definition of macro 'LABEL'
#define LABEL(constant) { #constant, constant }
^
jni/getevent.h:14:15: error: 'INPUT_PROP_BUTTONPAD' undeclared here (not in a function)
LABEL(INPUT_PROP_BUTTONPAD),
^
jni/getevent.h:8:38: note: in definition of macro 'LABEL'
#define LABEL(constant) { #constant, constant }
.................................
我用helper2416平臺的交叉編譯器單獨編譯getevent.c沒有錯誤,所以問題肯定處在android的編譯器上。
仔細查了下發現
/opt/android-ndk-r10d/platforms/android-3 目錄下根本沒有linux/input.h315直播頭文件(getevent.h中需要這個文件頭)
反而在/opt/android-ndk-r10d/platforms/android-21下有,所以想來是-I的目錄錯了。
手動執行編譯命令:
/opt/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -MMD -MP -MF ./obj/local/armeabi/objs/GetEvent/getevent.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Ijni -DANDROID -Wa,--noexecstack -Wformat -I/opt/android-ndk-r10d/platforms/android-21/arch-arm/usr/include -c jni/getevent.c -o ./obj/local/armeabi/objs/GetEvent/getevent.o
編譯成功,證實了自己的看法。
解決方法:
源碼目錄中 加上Application.mk文件
內容爲
APP_PLATFORM := android-21