protobuf版本为3.0.0。在某些设备(比如Android 6)中,这个问题总是会发生;而在一些设备(比如Android5.x)中,当应用程序被放到后台模式时,就会出现这个问题。
我调用以下方法:
bool ParseFromString(const string& data);
这可能在内部称为bool ParseFromArray(const void* data, int size)
。堆栈跟踪:
Build fingerprint: 'lge/b2lds_global_com/b2lds:5.0.2/LRX22G/152532131cf4c:user/release-keys'
Revision: '1.0'
ABI: 'arm'
pid: 9946, tid: 9970, name: ahlaad.saarathy >>> com.org.aahlaad.saarathy <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xdeadbaad
Abort message: 'invalid address or address of corrupt block 0xa19fca5c passed to dlfree'
r0 ffffffff r1 deadbaad r2 73797300 r3 2e6d6f63
r4 b6f2bfd8 r5 a19fca5c r6 a19469e4 r7 b6f310fc
r8 a19fca64 r9 a1c417b0 sl 00000000 fp a1946a64
ip 00000000 sp a19469a8 lr b6efe031 pc b6efe034 cpsr 800f0030
backtrace:
#00 pc 00027034 /system/lib/libc.so (__bionic_heap_usage_error+35)
#01 pc 00029853 /system/lib/libc.so (dlfree+1354)
#02 pc 0000f0e7 /system/lib/libc.so (free+10)
#03 pc 001bc24d /data/app/com.org.aahlaad.saarathy-1/lib/arm/libprotobuf.so
#04 pc 001bc4d7 /data/app/com.org.aahlaad.saarathy-1/lib/arm/libprotobuf.so
===> #05 pc 000dde37 /data/app/com.org.aahlaad.saarathy-1/lib/arm/libprotobuf.so (google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)+50)
#06 pc 00060944 /data/app/com.org.aahlaad.saarathy-1/lib/arm/libsaarathyclient.so (Saarathy::Messaging::Convey::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)+480)
#07 pc 000d7bdd /data/app/com.org.aahlaad.saarathy-1/lib/arm/libprotobuf.so (google::protobuf::MessageLite::ParseFromString(std::string const&)+48)
#08 pc 00022d84 /data/app/com.org.aahlaad.saarathy-1/lib/arm/libsaarathyclient.so (Connection::CloudSSL::DecodeProtoBuffer(unsigned int, std::string const&)+580)
#09 pc 00024f0c /data/app/com.org.aahlaad.saarathy-1/lib/arm/libsaarathyclient.so (Connection::CloudSSL::Receive()+308)
#10 pc 0002af68 /data/app/com.org.aahlaad.saarathy-1/lib/arm/libsaarathyclient.so (Util::Synchronized_<Connection::CloudSSL>::Start()::{lambda()#1}::operator()() const+72)
#11 pc 00091207 /data/app/com.org.aahlaad.saarathy-1/lib/arm/libgnustl_shared.so (execute_native_thread_routine+14)
#12 pc 00012f57 /system/lib/libc.so (__pthread_start(void*)+30)
#13 pc 00011017 /system/lib/libc.so (__start_thread+6)
显然,如箭头所示,它在google::protobuf::internal::WireFormatLite::ReadBytes(...)
崩溃。这个问题已经在这条线中讨论过了,用户通过将VS2005升级到VS2008来修复这个问题。然而,我们在Android中运行这一功能。
我亦曾提及以下职位,但均告无效:
任何详细的帮助都是非常感谢的,因为我在用Android构建原型库方面还是新手。
发布于 2016-05-11 23:23:24
我通过下面的步骤解决了上面的问题
步骤1:使用相同的NDK运行时stlport_shared或gnustl_shared,构建JNI源代码和Google C++源代码,我们可以在Application.mk文件中将其定义为
APP_STL := gnustl_shared
我使用gnustl-static
构建了我的JNI源代码,这引起了问题。如果您在构建Google源代码时使用不同的运行时,可能会出现问题。您可以在Android CPP支持指南上获得有关android运行时的更多信息。
步骤2:确保您的JNI代码和共享库(libprotobuf.so
)引用相同版本的Google库。它可能会在不同的android版本中导致未定义的行为。
您可以从Google Protobuf Git Repo下载最新的源代码
您可以遵循Android平台外部原型链接的构建步骤,或者为了简单起见,可以使用下面的"Andoid.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/csharp/csharp_doc_comment.cc \
google/protobuf/compiler/csharp/csharp_enum.cc \
google/protobuf/compiler/csharp/csharp_enum_field.cc \
google/protobuf/compiler/csharp/csharp_field_base.cc \
google/protobuf/compiler/csharp/csharp_generator.cc \
google/protobuf/compiler/csharp/csharp_helpers.cc \
google/protobuf/compiler/csharp/csharp_map_field.cc \
google/protobuf/compiler/csharp/csharp_message.cc \
google/protobuf/compiler/csharp/csharp_message_field.cc \
google/protobuf/compiler/csharp/csharp_primitive_field.cc \
google/protobuf/compiler/csharp/csharp_reflection_class.cc \
google/protobuf/compiler/csharp /csharp_repeated_enum_field.cc \
google/protobuf/compiler/csharp/csharp_repeated_message_field.cc \
google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc \
google/protobuf/compiler/csharp/csharp_source_generator_base.cc \
google/protobuf/compiler/csharp/csharp_wrapper_field.cc \
google/protobuf/compiler/java/java_context.cc \
google/protobuf/compiler/java/java_doc_comment.cc \
google/protobuf/compiler/java/java_enum.cc \
google/protobuf/compiler/java/java_enum_field.cc \
google/protobuf/compiler/java/java_enum_field_lite.cc \
google/protobuf/compiler/java/java_enum_lite.cc \
google/protobuf/compiler/java/java_extension.cc \
google/protobuf/compiler/java/java_field.cc \
google/protobuf/compiler/java/java_file.cc \
google/protobuf/compiler/java/java_generator.cc \
google/protobuf/compiler/java/java_generator_factory.cc \
google/protobuf/compiler/java/java_helpers.cc \
google/protobuf/compiler/java/java_lazy_message_field.cc \
google/protobuf/compiler/java/java_lazy_message_field_lite.cc \
google/protobuf/compiler/java/java_map_field.cc \
google/protobuf/compiler/java/java_map_field_lite.cc \
google/protobuf/compiler/java/java_message.cc \
google/protobuf/compiler/java/java_message_builder.cc \
google/protobuf/compiler/java/java_message_builder_lite.cc \
google/protobuf/compiler/java/java_message_field.cc \
google/protobuf/compiler/java/java_message_field_lite.cc \
google/protobuf/compiler/java/java_message_lite.cc \
google/protobuf/compiler/java/java_name_resolver.cc \
google/protobuf/compiler/java/java_primitive_field.cc \
google/protobuf/compiler/java/java_primitive_field_lite.cc \
google/protobuf/compiler/java/java_service.cc \
google/protobuf/compiler/java/java_shared_code_generator.cc \
google/protobuf/compiler/java/java_string_field.cc \
google/protobuf/compiler/java/java_string_field_lite.cc \
google/protobuf/compiler/javanano/javanano_enum.cc \
google/protobuf/compiler/javanano/javanano_enum_field.cc \
google/protobuf/compiler/javanano/javanano_extension.cc \
google/protobuf/compiler/javanano/javanano_field.cc \
google/protobuf/compiler/javanano/javanano_file.cc \
google/protobuf/compiler/javanano/javanano_generator.cc \
google/protobuf/compiler/javanano/javanano_helpers.cc \
google/protobuf/compiler/javanano/javanano_map_field.cc \
google/protobuf/compiler/javanano/javanano_message.cc \
google/protobuf/compiler/javanano/javanano_message_field.cc \
google/protobuf/compiler/javanano/javanano_primitive_field.cc \
google/protobuf/compiler/js/js_generator.cc \
google/protobuf/compiler/objectivec/objectivec_enum.cc \
google/protobuf/compiler/objectivec/objectivec_enum_field.cc \
google/protobuf/compiler/objectivec/objectivec_extension.cc \
google/protobuf/compiler/objectivec/objectivec_field.cc \
google/protobuf/compiler/objectivec/objectivec_file.cc \
google/protobuf/compiler/objectivec/objectivec_generator.cc \
google/protobuf/compiler/objectivec/objectivec_helpers.cc \
google/protobuf/compiler/objectivec/objectivec_map_field.cc \
google/protobuf/compiler/objectivec/objectivec_message.cc \
google/protobuf/compiler/objectivec/objectivec_message_field.cc \
google/protobuf/compiler/objectivec/objectivec_oneof.cc \
google/protobuf/compiler/objectivec/objectivec_primitive_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)
步骤3:需要向Android.mk添加波纹图标志的
LOCAL_CFLAGS += $(cf_includes) -DGOOGLE_PROTOBUF_NO_RTTI
参考链接Android独立工具链
使用上述步骤可以解决此问题。
https://stackoverflow.com/questions/37163821
复制相似问题