Closed
Description
ToolChains:
android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin
arm-linux-androideabi-g++ (GCC) 4.6 20120106 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
And I integrate JsonCpp in my project, include the amalgamated source (a single .cpp file and two .h files), build a shared library like this:
Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := JsonCpp
LOCAL_CPPFLAGS := -fexceptions
LOCAL_SRC_FILES := jsoncpp.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/..\
$(LOCAL_PATH)/json
LOCAL_EXPORT_CPPFLAGS := -I$(LOCAL_PATH)/json
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
Use the shared library like this:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := JsonTest
LOCAL_SRC_FILES := JsonTest.cpp
LOCAL_SHARED_LIBRARIES := JsonCpp
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)
The test code is:
int ParseJsonFromString()
{
const char* str = "{\"uploadid\": \"UP000000\",\"code\": 100,\"msg\": \"\",\"files\": \"\"}";
Json::Reader reader;
Json::Value root;
if (reader.parse(str, root))
{
std::string upload_id = root["uploadid"].asString();
int code = root["code"].asInt();
}
return 0;
}
Error Information
********** Crash dump: **********
Build fingerprint: 'Android/full_jacinto6evm/jacinto6evm:5.1.1/LMY47V/root09081358:userdebug/test-keys'
pid: 5523, tid: 5523, name: xample.jsontest >>> com.example.jsontest <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xb38009b0
Stack frame #00 pc 00049b3c /system/lib/libc.so (ifree+47)
Stack frame #01 pc 00012caf /system/lib/libc.so (free+10)
Stack frame #02 pc 0000585d /data/app/com.example.jsontest-2/lib/arm/libJsonTest.so: Routine std::string::_Rep::_M_dispose(std::allocator<char> const&) at /opt/Android/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/basic_string.h:244
Stack frame #03 pc 00005b8f /data/app/com.example.jsontest-2/lib/arm/libJsonTest.so (Java_com_example_jsontest_MainActivity_parseJsonString+26): Routine Java_com_example_jsontest_MainActivity_parseJsonString at /home/Project/TestCode/JsonTest/jni/JsonTest/JsonTest.cpp:107
Stack frame #04 pc 000524c3 /data/dalvik-cache/arm/data@app@com.example.jsontest-2@base.apk@classes.dex
But, If I build a static library, there is no segfault.