首先感谢
http://blog.sina.com.cn/s/blog_632dcf7501011us2.html 和
http://blog.sina.com.cn/s/blog_632dcf7501012bo0.html 给予了我很大的帮助。说说自己在编译过程中遇到的一些问题以及处理方法。
我的编译环境为 windows8 + NDK r8e, protoc buf 版本为2.5.0。
首先将protoc buf 目录里的\protobuf-2.5.0\src\google目录下的所有文件拷贝到jni目录下。目录结构图如下
然后将protobuf-2.5.0\vsprojects目录下的config.h文件拷贝到jni/google/protobuf/目录下。
配置android.mk,其详细内容如下
# Copyright (C) 2009 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_CPPFLAGS += -frtti LOCAL_MODULE := libnative LOCAL_CPP_EXTENSION := .cc .cpp #LOCAL_CPPFLAGS += -fexceptions #LOCAL_CFLAGS := -Werror LOCAL_SRC_FILES := NativeEntry.cpp \ google/protobuf/io/coded_stream.cc \ google/protobuf/stubs/common.cc \ google/protobuf/extension_set.cc \ google/protobuf/message_lite.cc \ google/protobuf/stubs/once.cc \ google/protobuf/repeated_field.cc \ google/protobuf/stubs/stringprintf.cc \ google/protobuf/wire_format_lite.cc \ google/protobuf/io/zero_copy_stream.cc \ google/protobuf/io/zero_copy_stream_impl_lite.cc \ LOCAL_C_INCLUDES += . \ $(LOCAL_PATH)/google \ $(LOCAL_PATH)/google/protobuf \ LOCAL_LDLIBS := -llog -ldl -lgcc -pthread \ D:/progrome_tools/adt-bundle-windows-x86_64/android-ndk-r8e-windows-x86_64/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/libgnustl_static.a ifndef NDK_ROOT include external/stlport/libstlport.mk endif include $(BUILD_SHARED_LIBRARY)
接下来配置Application.mk
# The ARMv7 is significanly faster due to the use of the hardware FPU APP_ABI := armeabi armeabi-v7a APP_PLATFORM := android-7 APP_STL := gnustl_static
然后修改config.h,注意网上有人建议不用修改config.h文件而是把backward_warning.h文件include进来.如果这样在编译的时候还是警告该文件以后的版本将不再使用。所以这种方式还是不可取,还是老老实实的修改config.h文件比较好。其config.h的文件内容如下
/* protobuf config.h for MSVC. On other platforms, this is generated * automatically by autoheader / autoconf / configure. */ /* the location of <hash_map> */ //#define HASH_MAP_H <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_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 1 /* define if you want to use zlib. See readme.txt for additional * requirements. */ // #define HAVE_ZLIB 1
接下就是在eclipse下配置ndk编译环境不需要cywin,具体方法请参见http://blog.csdn.net/maojudong/article/details/7261986