如何将最新的c ++ protobuf(3.2)与Android NDK集成/安装? [英] How to integrate/install latest c++ protobuf (3.2) with Android NDK?

查看:150
本文介绍了如何将最新的c ++ protobuf(3.2)与Android NDK集成/安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更容易地集成了较早的protobuf 3.0版。但是最新版本3.2存在问题。它只是编译&

如果我们遵循 git for c ++ proto &按照步骤进行构建,然后生成15 MB .SO文件,与之前的1-2 MB不同。

The earlier protobuf version 3.0 was easily integrated. But there are issues with the latest version 3.2. It simply compiles & builds all the un-related Android .cc file components as well.
If we follow the path to latest branch in git for c++ proto & build it as per the steps, then it generates 15 MB .SO file, unlike earlier which was ~1-2 MB.

如何将最新的protobuf最佳地集成到Android?

How to optimally integrate latest protobuf to Android?

推荐答案

使用跨平台 Android独立工具链和提供的构建脚本可能会导致共享库文件(.so)较大,这是由于构建脚本中包含不需要的文件而引起的。您可以创建自己的 Android.mk 文件,其中仅包含库的必需核心部分。生成的库文件可以用作其他Android项目中的预建库。请检查下面的步骤来创建第二个创建自己的脚本文件的选项。

Using cross platform Android Standalone Tool chain and provided build script may result in larger size of Shared library file(.so), generated due to unwanted files included in build script.You can create your own Android.mk file which includes only required core part of the library. Generated library files can be used as pre built library in other Android projects. Please check bellow steps for second option of creating own script files.


  1. Git源存储库

  2. 创建新的Android应用程序项目。在应用程序项目中通过名称 jni 创建目录。

  3. 从下载的源目录中运行以下命令。

  1. Download latest Android Google Protobuf source from Git Source Repository.
  2. Create New Android application project. Create directory by name jni inside application project.
  3. Run following commands from the downloaded source directory.




./ autogen.sh

./autogen.sh

./ configure

./configure




  1. 将下载的源代码放在 jni 目录中

  2. 将下面的Android.mk和Application.mk文件放在 jni 目录中。

  1. Place downloaded source code inside jni directory.
  2. Place bellow Android.mk and Application.mk file inside jni directory.

Android.mk

    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    c_includes := $(LOCAL_PATH)
    LOCAL_MODULE := libprotobuf      

    LOCAL_SRC_FILES := \
    google/protobuf/arena.cc \
    google/protobuf/arenastring.cc \
    google/protobuf/extension_set.cc \
    google/protobuf/generated_message_util.cc \
    google/protobuf/io/coded_stream.cc \
    google/protobuf/io/zero_copy_stream.cc \
    google/protobuf/io/zero_copy_stream_impl_lite.cc \
    google/protobuf/message_lite.cc \
    google/protobuf/repeated_field.cc \
    google/protobuf/stubs/atomicops_internals_x86_gcc.cc \
    google/protobuf/stubs/atomicops_internals_x86_msvc.cc \
    google/protobuf/stubs/bytestream.cc \
    google/protobuf/stubs/common.cc \
    google/protobuf/stubs/int128.cc \
    google/protobuf/stubs/once.cc \
    google/protobuf/stubs/status.cc \
    google/protobuf/stubs/statusor.cc \
    google/protobuf/stubs/stringpiece.cc \
    google/protobuf/stubs/stringprintf.cc \
    google/protobuf/stubs/structurally_valid.cc \
    google/protobuf/stubs/strutil.cc \
    google/protobuf/stubs/time.cc \
    google/protobuf/wire_format_lite.cc \
    google/protobuf/any.cc \
    google/protobuf/any.pb.cc \
    google/protobuf/api.pb.cc \
    google/protobuf/compiler/importer.cc \
    google/protobuf/compiler/parser.cc \
    google/protobuf/descriptor.cc \
    google/protobuf/descriptor.pb.cc \
    google/protobuf/descriptor_database.cc \
    google/protobuf/duration.pb.cc \
    google/protobuf/dynamic_message.cc \
    google/protobuf/empty.pb.cc \
    google/protobuf/extension_set_heavy.cc \
    google/protobuf/field_mask.pb.cc \
    google/protobuf/generated_message_reflection.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/map_field.cc \
    google/protobuf/message.cc \
    google/protobuf/reflection_ops.cc \
    google/protobuf/service.cc \
    google/protobuf/source_context.pb.cc \
    google/protobuf/struct.pb.cc \
    google/protobuf/stubs/mathlimits.cc \
    google/protobuf/stubs/substitute.cc \
    google/protobuf/text_format.cc \
    google/protobuf/timestamp.pb.cc \
    google/protobuf/type.pb.cc \
    google/protobuf/unknown_field_set.cc \
    google/protobuf/util/field_comparator.cc \
    google/protobuf/util/field_mask_util.cc \
    google/protobuf/util/internal/datapiece.cc \
    google/protobuf/util/internal/default_value_objectwriter.cc \
    google/protobuf/util/internal/error_listener.cc \
    google/protobuf/util/internal/field_mask_utility.cc \
    google/protobuf/util/internal/json_escaping.cc \
    google/protobuf/util/internal/json_objectwriter.cc \
    google/protobuf/util/internal/json_stream_parser.cc \
    google/protobuf/util/internal/object_writer.cc \
    google/protobuf/util/internal/proto_writer.cc \
    google/protobuf/util/internal/protostream_objectsource.cc \
    google/protobuf/util/internal/protostream_objectwriter.cc \
    google/protobuf/util/internal/type_info.cc \
    google/protobuf/util/internal/type_info_test_helper.cc \
    google/protobuf/util/internal/utility.cc \
    google/protobuf/util/json_util.cc \
    google/protobuf/util/message_differencer.cc \
    google/protobuf/util/time_util.cc \
    google/protobuf/util/type_resolver_util.cc \
    google/protobuf/wire_format.cc \
    google/protobuf/wrappers.pb.cc \
    google/protobuf/compiler/code_generator.cc      \
    google/protobuf/compiler/command_line_interface.cc      \
    google/protobuf/compiler/cpp/cpp_enum.cc      \
    google/protobuf/compiler/cpp/cpp_enum_field.cc      \
    google/protobuf/compiler/cpp/cpp_extension.cc      \
    google/protobuf/compiler/cpp/cpp_field.cc      \
    google/protobuf/compiler/cpp/cpp_file.cc      \
    google/protobuf/compiler/cpp/cpp_generator.cc      \
    google/protobuf/compiler/cpp/cpp_helpers.cc      \
    google/protobuf/compiler/cpp/cpp_map_field.cc      \
    google/protobuf/compiler/cpp/cpp_message.cc      \
    google/protobuf/compiler/cpp/cpp_message_field.cc      \
    google/protobuf/compiler/cpp/cpp_primitive_field.cc      \
    google/protobuf/compiler/cpp/cpp_service.cc      \
    google/protobuf/compiler/cpp/cpp_string_field.cc      \
    google/protobuf/compiler/plugin.cc      \
    google/protobuf/compiler/plugin.pb.cc      \
    google/protobuf/compiler/python/python_generator.cc      \
    google/protobuf/compiler/ruby/ruby_generator.cc      \
    google/protobuf/compiler/subprocess.cc      \
    google/protobuf/compiler/zip_writer.cc      \


    LOCAL_CFLAGS := -D GOOGLE_PROTOBUF_NO_RTTI=1
    LOCAL_CPPFLAGS := -std=c++11
    LOCAL_C_INCLUDES = $(LOCAL_PATH)/android 
    LOCAL_C_INCLUDES += ${ANDROID_NDK}/sources/cxx-stl/gnu-        libstdc++/4.8/include
    LOCAL_LDLIBS += -lz
    LOCAL_EXPORT_LDLIBS += -lz
    LOCAL_EXPORT_CFLAGS := $(LOCAL_CFLAGS)
    LOCAL_EXPORT_CPPFLAGS := $(LOCAL_CPPFLAGS)
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)


    include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL :=gnustl_shared # gnustl_static
NDK_TOOLCHAIN_VERSION := 4.9
APP_ABI := all
LIBCXX_FORCE_REBUILD := true
APP_PLATFORM:=android-9
NDK_DEBUG:=1




  1. 运行 ndk-build 并需要.so文件将在项目目录的 libs 文件夹内生成。

  1. Run ndk-build and required .so files will be generated inside libs folder of the project directory.

这篇关于如何将最新的c ++ protobuf(3.2)与Android NDK集成/安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆