Android NDK编译protobuf


其实用NDK编译最大的难点就是make文件,把这个搞定就基本搞定了


好了,现在开始吧

一、安装java环境和NDK环境(不多说,自己准备)

二、下载protobuf代码(http://code.google.com/p/protobuf/downloads/list

三、建立java的android工程,在根目录下简历jni目录,把protobuf代码解压到jni目录下

如图:

Android NDK下编译google protocol buffer_第1张图片


四、写application.mk文件,这个有个问题,protobuf需要使用gnustl_static,我替你写好了,直接复制过去吧,平台不如不一样,修改一下

APP_PLATFORM := android-9
#APP_STL := stlport_static
APP_STL := gnustl_static


五、开始写android.mk文件

这个是个大难题了,打开文件结构一看,各种文件都有,也不知道要包含哪些,而且有些文件是编译不过的(可能是google的测试代码),所以这个就成了最大问题了

没关系,在各种痛苦的时候我突然想到了一个办法,并且最后成功的编译出来了

我想到了在windows下,用vs2008打开protobuf的代码时,下面有好几个工程,而对我们有用的其实只有一个,就是libprotobuf

Android NDK下编译google protocol buffer_第2张图片
所以,打开这个工程,看看里面都有什么.c和.cc或.cpp文件,把所有文件写进make文件去就好了,然后把头文件目录加进去,OK,打工告成


为了方便大家,我把我的make文件提出来给大家吧,我是把protobuf编译给其他程序使用,所以只生成了.a文件,用来做动态连接,需要生成.so的人需要稍微修改一下

android.mk:


LOCAL_PATH := $(call my-dir)




################## Build ProtoBuf ################
include $(CLEAR_VARS)


LOCAL_ARM_MODE := arm
LOCAL_CPPFLAGS += -frtti
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE := libProtobuf
LOCAL_MODULE_TAGS := optional
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := \
protobuf-2.4.1/src/google/protobuf/io/coded_stream.cc \
protobuf-2.4.1/src/google/protobuf/stubs/common.cc \
protobuf-2.4.1/src/google/protobuf/descriptor.cc \
protobuf-2.4.1/src/google/protobuf/descriptor.pb.cc \
protobuf-2.4.1/src/google/protobuf/descriptor_database.cc \
protobuf-2.4.1/src/google/protobuf/dynamic_message.cc \
protobuf-2.4.1/src/google/protobuf/extension_set.cc \
protobuf-2.4.1/src/google/protobuf/extension_set_heavy.cc \
protobuf-2.4.1/src/google/protobuf/generated_message_reflection.cc \
protobuf-2.4.1/src/google/protobuf/generated_message_util.cc \
protobuf-2.4.1/src/google/protobuf/io/gzip_stream.cc \
protobuf-2.4.1/src/google/protobuf/compiler/importer.cc \
protobuf-2.4.1/src/google/protobuf/message.cc \
protobuf-2.4.1/src/google/protobuf/message_lite.cc \
protobuf-2.4.1/src/google/protobuf/stubs/once.cc \
protobuf-2.4.1/src/google/protobuf/compiler/parser.cc \
protobuf-2.4.1/src/google/protobuf/io/printer.cc \
protobuf-2.4.1/src/google/protobuf/reflection_ops.cc \
protobuf-2.4.1/src/google/protobuf/repeated_field.cc \
protobuf-2.4.1/src/google/protobuf/service.cc \
protobuf-2.4.1/src/google/protobuf/stubs/structurally_valid.cc \
protobuf-2.4.1/src/google/protobuf/stubs/strutil.cc \
protobuf-2.4.1/src/google/protobuf/stubs/substitute.cc \
protobuf-2.4.1/src/google/protobuf/text_format.cc \
protobuf-2.4.1/src/google/protobuf/io/tokenizer.cc \
protobuf-2.4.1/src/google/protobuf/unknown_field_set.cc \
protobuf-2.4.1/src/google/protobuf/wire_format.cc \
protobuf-2.4.1/src/google/protobuf/wire_format_lite.cc \
protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.cc \
protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.cc \
protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.cc \


LOCAL_C_INCLUDES += . \
$(LOCAL_PATH)/protobuf-2.4.1/src \
$(LOCAL_PATH)/protobuf-2.4.1 \
#$(LOCAL_PATH)/protobuf-2.4.1/vsprojects \





LOCAL_LDLIBS := -llog -lgcc -pthread \
C:/android-ndk-r6/sources/cxx-stl/gnu-libstdc++/libs/armeabi/libstdc++.a \


ifndef NDK_ROOT
include external/stlport/libstlport.mk
endif
include $(BUILD_STATIC_LIBRARY)



六、cygwin到android工程目录,执行ndk-build即可



更多相关文章

  1. Android studio中Git的学习和使用心得(二)在Android studio中如何
  2. Android Eclipse JNI 调用 .so文件加载问题
  3. Android之Layout资源文件
  4. Android实战技巧:使用原始资源文件
  5. Android Studio代码调试大全
  6. Android 实现闪屏页和右上角的倒计时跳转实例代码

随机推荐

  1. [jquery]如何实现页面单块DIV区域滚动展
  2. (文件).ready是全球范围的吗?
  3. TypeError:e。getPosition不是一个函数。
  4. 创建一个未排序的数组,其中包含重复元素和
  5. 如何停止基于CSS值的jquery动画?
  6. js不使用jquery,调用ajax,传递数组,并接
  7. 网页标签功能插: jQuery tags input 翻
  8. 可编辑的表格:jQuery+PHP实现实时编辑表格
  9. 如何让jQuery post与salesforce的WebToLe
  10. 为什么我不能在同一个js文件中建立两个cl