我从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


更多相关文章

  1. Android(安卓)Studio下“Error:Could not find com.android.tool
  2. Android(安卓)2.1 源码结构分析
  3. Android(安卓)学习之Layout
  4. android studio运行应用报找不到资源问题
  5. Android全工程编译不过问题汇总
  6. Android(安卓)源码编译make的错误处理
  7. Android系统定制源码修改 - MTK平台
  8. 修改Android(安卓)framework定制重启功能
  9. android源码解析-异步消息

随机推荐

  1. Android Activity和Intent机制学习笔记
  2. 谷歌退出中国,android在中国的前途如何?
  3. Android(安卓)初始化NavigationView的hea
  4. android中数据存储
  5. 【Android】学习记录 -- 初识ffmpeg
  6. AndroidStudio Unknown attribute androi
  7. android之focusable的使用
  8. Android横屏预竖屏
  9. 移动端H5的Video标签无法播放在线视频的
  10. 使用Android Studio调试smail源码