先说下我的工程目录
ProjectName
src
core
share
proj.android
jni
…
sdk
protobuf-2.4.1
src
…
从Google code下载protobuf-2.4.1源码包, 解压, 在protobuf-2.4.1目录下添加Android.mk, 内容如下
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := protobuf-2.4.1
LOCAL_SRC_FILES :=
src/google/protobuf/io/coded_stream.cc
src/google/protobuf/io/printer.cc
src/google/protobuf/io/gzip_stream.cc
src/google/protobuf/io/tokenizer.cc
src/google/protobuf/io/zero_copy_stream.cc
src/google/protobuf/io/zero_copy_stream_impl.cc
src/google/protobuf/io/zero_copy_stream_impl_lite.cc
src/google/protobuf/stubs/common.cc
src/google/protobuf/stubs/once.cc
src/google/protobuf/stubs/structurally_valid.cc
src/google/protobuf/stubs/strutil.cc
src/google/protobuf/stubs/substitute.cc
src/google/protobuf/compiler/importer.cc
src/google/protobuf/compiler/parser.cc
src/google/protobuf/descriptor.cc
src/google/protobuf/descriptor.pb.cc
src/google/protobuf/descriptor_database.cc
src/google/protobuf/dynamic_message.cc
src/google/protobuf/extension_set.cc
src/google/protobuf/extension_set_heavy.cc
src/google/protobuf/generated_message_reflection.cc
src/google/protobuf/generated_message_util.cc
src/google/protobuf/message.cc
src/google/protobuf/message_lite.cc
src/google/protobuf/reflection_ops.cc
src/google/protobuf/repeated_field.cc
src/google/protobuf/service.cc
src/google/protobuf/text_format.cc
src/google/protobuf/unknown_field_set.cc
src/google/protobuf/wire_format.cc
src/google/protobuf/wire_format_lite.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)
$(LOCAL_PATH)/src
include $(BUILD_STATIC_LIBRARY)
此时编译会报config.h找不到的错误, 这个文件在vsproject目录有, 但只是VC编译使用, 这篇文章说需要手动创建, 但实际上, Linux下可以通过config系统自动生成的, 但是Android平台下,不使用cygwin时, 就需要自己手动创建config.h, 内容如下
/*
This make file is only for android ONLY, modified by Davy Xu June 17, 2013
Cause android platform can't use linux config system when cygwin envirement is not available
*/
/* the location of <hash_set> */
#define HASH_SET_H <ext/hash_set>
#define HASH_MAP_H <ext/hash_map>
#define HASH_NAMESPACE __gnu_cxx
/* define if the compiler has hash_map */
//#define HAVE_HASH_MAP 1
/* define if the compiler has hash_set */
//#define HAVE_HASH_SET 1
#define HAVE_PTHREAD
剩下的事情就简单了, 在你的工程Android.mk里添加protobuf的引用
例如:
LOCAL_WHOLE_STATIC_LIBRARIES += protobuf-2.4.1
$(call import-module,protobuf-2.4.1)
还要在NDK_MODULE_PATH中增加搜索路径D:DevelopProjectNamesdk
注意, 这里protobuf-2.4.1名称必须与sdk下的文件夹名, LOCAL_MODULE中的名称保持一致, 否则搜索不到
网友评论已有0条评论, 我也要评论