Android进阶之路Android开发经验谈Android技术知识

protobuf 的ndk编译问题

2019-10-31  本文已影响0人  寒江楓雨

1 下载protobuf源码,我用的版本是2.6.0,并把google/protobuf 整个目录拷贝到src/main/jni目录下
2 修改config.h文件,如下:

#define HASH_MAP_H <ext/hash_map>
/* the namespace of hash_map/hash_set */
// Apparently Microsoft decided to move hash_map *back* to the std namespace
// in MSVC 2010:
//   http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx
// TODO(kenton):  Use unordered_map instead, which is available in MSVC 2010.
#if _MSC_VER < 1310 || _MSC_VER >= 1600
#define HASH_NAMESPACE std
#else
#define HASH_NAMESPACE stdext
#endif

/* the location of <hash_set> */
#define HASH_SET_H <ext/hash_set>
#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 if you want to use zlib.  See readme.txt for additional
 * requirements. */
// #define HAVE_ZLIB 1

#define HAVE_PTHREAD

3 添加Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := protobuf
LOCAL_CFLAGS := -std=c++11 -fexceptions -frtti
LOCAL_MODULE_FILENAME := libprotobuf
LOCAL_SRC_FILES :=  \
            google/config.h  \
            google/protobuf/stubs/atomicops_internals_x86_gcc.cc         \
            google/protobuf/stubs/atomicops_internals_x86_msvc.cc        \
            google/protobuf/stubs/common.cc                              \
            google/protobuf/stubs/once.cc                                \
            google/protobuf/stubs/hash.h                                 \
            google/protobuf/stubs/map_util.h                             \
            google/protobuf/stubs/shared_ptr.h                           \
            google/protobuf/stubs/stringprintf.cc                        \
            google/protobuf/stubs/stringprintf.h                         \
            google/protobuf/extension_set.cc                             \
            google/protobuf/generated_message_util.cc                    \
            google/protobuf/message_lite.cc                              \
            google/protobuf/repeated_field.cc                            \
            google/protobuf/wire_format_lite.cc                          \
            google/protobuf/io/coded_stream.cc                           \
            google/protobuf/io/coded_stream_inl.h                        \
            google/protobuf/io/zero_copy_stream.cc                       \
            google/protobuf/io/zero_copy_stream_impl_lite.cc             \
            google/protobuf/stubs/strutil.cc                             \
            google/protobuf/stubs/strutil.h                              \
            google/protobuf/stubs/substitute.cc                          \
            google/protobuf/stubs/substitute.h                           \
            google/protobuf/stubs/structurally_valid.cc                  \
            google/protobuf/descriptor.cc                                \
            google/protobuf/descriptor.pb.cc                             \
            google/protobuf/descriptor_database.cc                       \
            google/protobuf/dynamic_message.cc                           \
            google/protobuf/extension_set_heavy.cc                       \
            google/protobuf/generated_message_reflection.cc              \
            google/protobuf/message.cc                                   \
            google/protobuf/reflection_ops.cc                            \
            google/protobuf/service.cc                                   \
            google/protobuf/text_format.cc                               \
            google/protobuf/unknown_field_set.cc                         \
            google/protobuf/wire_format.cc                               \
            google/protobuf/io/gzip_stream.cc                            \
            google/protobuf/io/printer.cc                                \
            google/protobuf/io/strtod.cc                                 \
            google/protobuf/io/tokenizer.cc                              \
            google/protobuf/io/zero_copy_stream_impl.cc                  \
            google/protobuf/compiler/importer.cc                         \
            google/protobuf/compiler/parser.cc


LOCAL_EXPORT_C_INCLUDES :=
LOCAL_EXPORT_LDLIBS :=

LOCAL_C_INCLUDES := $(LOCAL_PATH)/google/config.h  \
$(LOCAL_PATH)/src

LOCAL_LDLIBS := -llog -lz

include $(BUILD_SHARED_LIBRARY)
#include $(BUILD_STATIC_LIBRARY)

4 添加Appliction.mk

APP_MODULES      := protobuf
APP_PLATFORM     := android-19
APP_ABI          := all
APP_STL := c++_static
APP_OPTIM        := release

5 在jni目录下执行ndk-build即可。

上一篇 下一篇

猜你喜欢

热点阅读