diff --git a/android/build.gradle b/android/build.gradle index 11fadc97c9..4e1080fff4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -419,3 +419,8 @@ task obbPush(dependsOn: ['obbGenerate', 'obbPushMain', 'obbPushPatch']) { commandLine android.getAdbExe(), 'push', propObbWorldsOutput, "${obbPath}worlds.obb" } } + +task patchNdkR10E(type: Exec, description: 'Patches NDK r10e for bug described here https://code.google.com/p/android/issues/detail?id=179410') { + def cxxabiPath = "${android.getNdkDirectory().getAbsolutePath()}/sources/cxx-stl/gabi++/src/cxxabi.cc" + commandLine 'bash', '-c', "patch -p1 ${cxxabiPath} < ../tools/android/cxxabi.cc_patch" +} diff --git a/android/jni/Application.mk b/android/jni/Application.mk index b4b8057648..3cfe2d9e97 100644 --- a/android/jni/Application.mk +++ b/android/jni/Application.mk @@ -1,4 +1,4 @@ -NDK_TOOLCHAIN_VERSION := clang +NDK_TOOLCHAIN_VERSION := clang3.6 APP_PLATFORM := android-15 APP_STL := c++_static @@ -28,5 +28,12 @@ else APP_CFLAGS += -DRELEASE -D_RELEASE ifeq ($(PRODUCTION),1) APP_CFLAGS += -DOMIM_PRODUCTION + # Temporary workaround for crashes on x86 arch when throwing C++ exceptions, built with NDK r10e version. + # Requires patched NDK file "android-ndk-r10e/sources/cxx-stl/gabi++/src/cxxabi.cc" file, + # Patch can be found at "../tools/android/cxxabi.cc_patch". + # Gradle task patchNdkR10E will patch it for you. + # More details here: https://code.google.com/p/android/issues/detail?id=179410. + # TODO: Check if this workaround is needed in newer NDK versions. + LIBCXX_FORCE_REBUILD := true endif endif diff --git a/tools/android/cxxabi.cc_patch b/tools/android/cxxabi.cc_patch new file mode 100644 index 0000000000..79412c529e --- /dev/null +++ b/tools/android/cxxabi.cc_patch @@ -0,0 +1,15 @@ +diff --git a/Users/yunik/devtools/android-sdk/ndk-bundle/sources/cxx-stl/gabi++/src/cxxabi.cc b/android/../tools/android/cxxabi.cc +index 3f428d9..9c0e8bc 100644 +--- a/Users/yunik/devtools/android-sdk/ndk-bundle/sources/cxx-stl/gabi++/src/cxxabi.cc ++++ b/android/../tools/android/cxxabi.cc +@@ -296,7 +296,9 @@ namespace __cxxabiv1 { + + extern "C" void *__cxa_allocate_exception(size_t thrown_size) _GABIXX_NOEXCEPT { + size_t size = thrown_size + sizeof(__cxa_exception); +- __cxa_exception *buffer = static_cast<__cxa_exception*>(malloc(size)); ++ // Bugfix for crashes appearing on stack unwinding, taken from https://android-review.googlesource.com/#/c/182443/ ++ //__cxa_exception *buffer = static_cast<__cxa_exception*>(malloc(size)); ++ __cxa_exception *buffer = static_cast<__cxa_exception*>(memalign(__alignof__(__cxa_exception), size)); + if (!buffer) { + // Since Android uses memory-overcommit, we enter here only when + // the exception object is VERY large. This will propably never happen. diff --git a/tools/mkspecs/android-clang/qmake.conf b/tools/mkspecs/android-clang/qmake.conf index 6c498513b6..be8b5ffc5e 100644 --- a/tools/mkspecs/android-clang/qmake.conf +++ b/tools/mkspecs/android-clang/qmake.conf @@ -5,18 +5,19 @@ ######################################################################### ANDROID_TARGET_ABI = $$(NDK_ABI) -# By default use armv7 architecture with hardware math co-processor. -isEmpty( ANDROID_TARGET_ABI ): ANDROID_TARGET_ABI = armeabi-v7a-hard +# By default use armv7 architecture. +isEmpty( ANDROID_TARGET_ABI ): ANDROID_TARGET_ABI = armeabi-v7a # Minimum supported platform is Android 4.0.3. ANDROID_PLATFORM = android-15 -GCC_VERSION = 4.9 +GCC_VERSION = 4.8 +CLANG_VERSION = 3.6 MAKEFILE_GENERATOR = UNIX -QMAKE_COMPILER = $$(NDK_ROOT)/toolchains/llvm/prebuilt/$$(NDK_HOST)/bin/clang +QMAKE_COMPILER = $$(NDK_ROOT)/toolchains/llvm-$$CLANG_VERSION/prebuilt/$$(NDK_HOST)/bin/clang QMAKE_CC = $$QMAKE_COMPILER -QMAKE_CXX = $$(NDK_ROOT)/toolchains/llvm/prebuilt/$$(NDK_HOST)/bin/clang++ +QMAKE_CXX = $$(NDK_ROOT)/toolchains/llvm-$$CLANG_VERSION/prebuilt/$$(NDK_HOST)/bin/clang++ QMAKE_LINK_C = $$QMAKE_CC QMAKE_LINK_C_SHLIB = $$QMAKE_CC QMAKE_LINK = $$QMAKE_CXX