Tôi muốn tạo phiên bản gốc của thư viện bộ đệm giao thức của Google.
Tôi sẽ làm như thế nào?Cách tạo bộ đệm giao thức theo Android NDK
Trả lời
tôi Sử dụng Android.mk này và xây dựng SUCCESSFUL
# 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)
CC_LITE_SRC_FILES := \
src/google/protobuf/stubs/common.cc \
src/google/protobuf/stubs/once.cc \
src/google/protobuf/stubs/hash.cc \
src/google/protobuf/extension_set.cc \
src/google/protobuf/generated_message_util.cc \
src/google/protobuf/message_lite.cc \
src/google/protobuf/repeated_field.cc \
src/google/protobuf/wire_format_lite.cc \
src/google/protobuf/io/coded_stream.cc \
src/google/protobuf/io/zero_copy_stream.cc \
src/google/protobuf/io/zero_copy_stream_impl_lite.cc
COMPILER_SRC_FILES := \
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 \
src/google/protobuf/compiler/code_generator.cc \
src/google/protobuf/compiler/command_line_interface.cc \
src/google/protobuf/compiler/importer.cc \
src/google/protobuf/compiler/main.cc \
src/google/protobuf/compiler/parser.cc \
src/google/protobuf/compiler/plugin.cc \
src/google/protobuf/compiler/plugin.pb.cc \
src/google/protobuf/compiler/subprocess.cc \
src/google/protobuf/compiler/zip_writer.cc \
src/google/protobuf/compiler/cpp/cpp_enum.cc \
src/google/protobuf/compiler/cpp/cpp_enum_field.cc \
src/google/protobuf/compiler/cpp/cpp_extension.cc \
src/google/protobuf/compiler/cpp/cpp_field.cc \
src/google/protobuf/compiler/cpp/cpp_file.cc \
src/google/protobuf/compiler/cpp/cpp_generator.cc \
src/google/protobuf/compiler/cpp/cpp_helpers.cc \
src/google/protobuf/compiler/cpp/cpp_message.cc \
src/google/protobuf/compiler/cpp/cpp_message_field.cc \
src/google/protobuf/compiler/cpp/cpp_primitive_field.cc \
src/google/protobuf/compiler/cpp/cpp_service.cc \
src/google/protobuf/compiler/cpp/cpp_string_field.cc \
src/google/protobuf/compiler/java/java_enum.cc \
src/google/protobuf/compiler/java/java_enum_field.cc \
src/google/protobuf/compiler/java/java_extension.cc \
src/google/protobuf/compiler/java/java_field.cc \
src/google/protobuf/compiler/java/java_file.cc \
src/google/protobuf/compiler/java/java_generator.cc \
src/google/protobuf/compiler/java/java_helpers.cc \
src/google/protobuf/compiler/java/java_message.cc \
src/google/protobuf/compiler/java/java_message_field.cc \
src/google/protobuf/compiler/java/java_primitive_field.cc \
src/google/protobuf/compiler/java/java_service.cc \
src/google/protobuf/compiler/javamicro/javamicro_enum.cc \
src/google/protobuf/compiler/javamicro/javamicro_enum_field.cc \
src/google/protobuf/compiler/javamicro/javamicro_field.cc \
src/google/protobuf/compiler/javamicro/javamicro_file.cc \
src/google/protobuf/compiler/javamicro/javamicro_generator.cc \
src/google/protobuf/compiler/javamicro/javamicro_helpers.cc \
src/google/protobuf/compiler/javamicro/javamicro_message.cc \
src/google/protobuf/compiler/javamicro/javamicro_message_field.cc \
src/google/protobuf/compiler/javamicro/javamicro_primitive_field.cc \
src/google/protobuf/compiler/python/python_generator.cc \
src/google/protobuf/io/coded_stream.cc \
src/google/protobuf/io/gzip_stream.cc \
src/google/protobuf/io/printer.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/hash.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
# C++ full library
# =======================================================
#include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_MODULE_TAGS := optional
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := \
$(CC_LITE_SRC_FILES) \
src/google/protobuf/stubs/strutil.cc \
src/google/protobuf/stubs/substitute.cc \
src/google/protobuf/stubs/structurally_valid.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_heavy.cc \
src/google/protobuf/generated_message_reflection.cc \
src/google/protobuf/message.cc \
src/google/protobuf/reflection_ops.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/io/gzip_stream.cc \
src/google/protobuf/io/printer.cc \
src/google/protobuf/io/tokenizer.cc \
src/google/protobuf/io/zero_copy_stream_impl.cc \
src/google/protobuf/compiler/importer.cc \
src/google/protobuf/compiler/parser.cc
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/src
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/android \
bionic \
$(LOCAL_PATH)/src \
$(JNI_H_INCLUDE)
LOCAL_SHARED_LIBRARIES := \
libz libcutils libutils
LOCAL_LDLIBS := -lz
# stlport conflicts with the host stl library
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_C_INCLUDES += external/stlport/stlport
LOCAL_SHARED_LIBRARIES += libstlport
endif
# Define the header files to be copied
#LOCAL_COPY_HEADERS := \
# src/google/protobuf/stubs/once.h \
# src/google/protobuf/stubs/common.h \
# src/google/protobuf/io/coded_stream.h \
# src/google/protobuf/generated_message_util.h \
# src/google/protobuf/repeated_field.h \
# src/google/protobuf/extension_set.h \
# src/google/protobuf/wire_format_lite_inl.h
#
#LOCAL_COPY_HEADERS_TO := $(LOCAL_MODULE)
LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI
include $(BUILD_SHARED_LIBRARY)
Điều này hơi lỗi thời. Đối với protobuf 2.4.1 hash.cc không tồn tại, do đó, nó cần được loại bỏ. Nếu đi lên đến protobug 2.5.0, cùng một thỏa thuận cộng với bạn cần phải thêm src/google/protobuf/stubs/stringprintf.cc – gkanwar
@gkanwar khi tôi thực hiện các chỉnh sửa bạn đề xuất, biên dịch lib nhưng tôi nhận được lỗi này khi tôi cố gắng gọi phương thức của tôi phụ thuộc vào libs protobuf: Gây ra bởi: java.lang.UnsatisfiedLinkError: Không thể tải thư viện: reloc_library [1306]: 37 không thể định vị 'strtof' ... sử dụng "nm" Tôi nhận thấy phương thức strtof được liệt kê nhưng có "U" được liệt kê bên cạnh. Có thư viện nào mà tôi không bao gồm điều đó là cần thiết để protobuf hoạt động không? –
@MichaelNguyen strtof nên sống trong thư viện stl. libprotobuf sử dụng stlport; tệp xây dựng được mô tả trong câu trả lời liên kết nó như một thư viện được chia sẻ chứ không phải là tĩnh, vì vậy bạn cũng nên tải libstlport từ Java. Bạn có thể tìm thấy ví dụ hoạt động trong dự án tôi đang làm việc tại đây: https://github.com/IDKJava/the-elements/blob/master/TheElements-dev/src/com/idkjava/thelements/MainActivity.java # L605 – gkanwar
Android.mk nêu trên hoạt động tốt, cảm ơn rất nhiều.
Tôi muốn mô tả tất cả các bước để xây dựng protobuf cho android.
Định cấu hình nguồn cho Android. Sử dụng đoạn mã sau (đã nhận nó ở đây: http://habrahabr.ru/post/119693/):
dựng sẵn =/Users/người dùng/android-ndk-r7b/toolchains/cánh tay-linux-androideabi-4.4.3
PLATFORM =/Users/người dùng/android-ndk-r7b/nền tảng/android-3/arch-arm/
xuất CC = "/ Người dùng/người dùng/android-ndk-r7b/toolchains/arm-linux-androideabi- 4.4.3/dựng sẵn/darwin-x86/bin/tay-linux-androideabi-gcc"
CFLAGS xuất khẩu = "- fPIC -DANDROID -nostdlib"
xuất ANDROID_ROOT = "/ Người dùng/người dùng/android-ndk-r7b"
xuất LDFLAGS = "- Wl, -rpath-link = $ ANDROID_ROOT/platforms/android-3/arch-arm/usr/lib/-L $ ANDROID_ROOT/nền tảng/android-3/arch-cánh tay/usr/lib /"
xuất khẩu CPPFLAGS = "- tôi $ ANDROID_ROOT/nền tảng/android-3/arch-cánh tay/usr/include /"
xuất khẩu libs = "- lc"
./configure --host = tay-EABI
Xóa các dòng fr sau om được đề cập ở trên tệp Android.mk:
src/google/protobuf/stubs/strutil.cc \ src/google/protobuf/stubs/substitute.cc \ src/google/protobuf/stubs/structurally_valid.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_heavy.cc \ src/google/protobuf/generated_message_reflection.cc \ src/google/protobuf/message.cc \ src/google/protobuf/reflection_ops.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/io/gzip_stream.cc \ src/google/protobuf/io/printer.cc \ src/google/protobuf/io/tokenizer.cc \ src/google/protobuf/io/zero_copy_stream_impl.cc \ src/google/protobuf/compiler/importer.cc \ src/google/protobuf/compiler/parser.cc
Cần thiết để xây dựng phiên bản lite của thư viện. Thật không may phiên bản đầy đủ của lib hoạt động chỉ từ Android 2.3. Tôi đã thử nghiệm phiên bản lite cho Android 1.6, 2.1, 2.3.
- xây dựng thư viện bằng cách sử dụng ndk-build.
- để tạo tệp c + + (sử dụng trình biên dịch protoc) cho thư viện lite cần có để bao gồm: tùy chọn optimize_for = LITE_RUNTIME; trong tệp .proto.
khi tôi xóa các dòng đã đề cập, tôi nhận được lỗi biên dịch. Bạn có chắc chắn rằng những dòng này cần phải được loại bỏ? –
Dường như bạn đã quên đặt sysroot tại CPPFLAGS: 'xuất SYSROOT = $ NDK_ROOT/nền tảng/android-9/arch-arm' ' xuất CPPFLAGS = "- sysroot = $ SYSROOT" ' ' ./configure tùy chọn' –
- 1. Bộ đệm giao thức Delphi?
- 2. Bộ đệm giao thức Scala biên dịch
- 3. Bộ đệm giao thức với JPA
- 4. Boost.Asio với bộ đệm giao thức google
- 5. Từ điển trong bộ đệm giao thức
- 6. Bộ đệm giao thức Google so sánh
- 7. Dữ liệu/bộ đệm đệm giao thức Dump
- 8. Bộ đệm giao thức: Cách xác định loại ngày?
- 9. C++ Bộ đệm giao thức của Google: serialize thành char *?
- 10. Các giải pháp thay thế cho Bộ đệm giao thức
- 11. Cài đặt bộ đệm giao thức trên Windows
- 12. Ghi tăng dần đối tượng Bộ đệm Giao thức
- 13. Bộ đệm giao thức của Google - Bộ đệm kích thước cố định?
- 14. Bộ đệm giao thức của Google được biên dịch
- 15. Bộ đệm giao thức của Google so với ASN.1
- 16. Trường lặp lại Bộ đệm giao thức của Google C++
- 17. Bộ đệm giao thức của Google rất lớn trong python
- 18. Mở rộng bộ đệm giao thức trong Java
- 19. Bộ đếm thời gian NDK của Android
- 20. Cách tạo nhiều dự án theo thứ tự phụ thuộc chính xác với NDK của Android?
- 21. Sử dụng bộ đệm Giao thức làm đối tượng Dữ liệu chung?
- 22. Trong Bộ đệm giao thức của Google, tệp/mô hình giao thức phù hợp cho Ngoại lệ là gì?
- 23. Nhập định nghĩa bộ đệm giao thức giữa các dự án Maven
- 24. tại sao byte đệm giao thức là chuỗi trong c + +?
- 25. Phân tích cú pháp trong tệp văn bản cho Bộ đệm giao thức của Google
- 26. Tạo HBITMAP từ bộ đệm
- 27. sử dụng swig để liên kết bộ đệm giao thức google
- 28. Thông báo bộ đệm giao thức qua Akka IO và Sockets
- 29. Thiếu tệp đầu vào với protoc trong bộ đệm giao thức
- 30. Giao thức LLCP của Android Beam
Chỉ là một gợi ý. Đầu tiên, hãy xây dựng nó trong Java, và sau đó nếu bạn cần di chuyển tối ưu hơn nữa vào NDK. Ít nhất trong Java, bạn sẽ nhận được giao thức cơ bản xuống. – arunkumar
Bạn đã thử sử dụng cài đặt C++ do google cung cấp chưa? –
Đây là câu trả lời của tôi: https://stackoverflow.com/a/44773137/529442 –