From a06307434693e30d7fb68a522f3517d9b9083b57 Mon Sep 17 00:00:00 2001 From: Tiago Quendera Date: Fri, 17 Aug 2018 12:08:17 +0100 Subject: [PATCH 1/4] Update detect.py Fixed a typo in detect.py (cherry picked from commit aa594614db4087be68be5c991155795a804eb146) --- platform/android/detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/detect.py b/platform/android/detect.py index 971368db179..bbef3519de3 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -128,7 +128,7 @@ def configure(env): env.extra_suffix = ".armv7" + env.extra_suffix elif env["android_arch"] == "arm64v8": if get_platform(env["ndk_platform"]) < 21: - print("WARNING: android_arch=arm64v8 is not supported by ndk_platform lower than andorid-21; setting ndk_platform=android-21") + print("WARNING: android_arch=arm64v8 is not supported by ndk_platform lower than android-21; setting ndk_platform=android-21") env["ndk_platform"] = "android-21" env['ARCH'] = 'arch-arm64' target_subpath = "aarch64-linux-android-4.9" From d3ca68aee4b17066ac8eb535ac7d76a4237841c9 Mon Sep 17 00:00:00 2001 From: Ridwan Abdul Hafidh Date: Thu, 23 Aug 2018 05:02:47 +0700 Subject: [PATCH 2/4] add support libc++_shared stl on android (cherry picked from commit b0419db46f52a3b606acb985265bcd56ec1dad7c) --- platform/android/SCsub | 6 ++++++ platform/android/detect.py | 33 +++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/platform/android/SCsub b/platform/android/SCsub index da03054ff65..84f5ceeca5f 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -2,6 +2,8 @@ import shutil from compat import open_utf8 +from distutils.version import LooseVersion +from detect import get_ndk_version Import('env') @@ -169,3 +171,7 @@ if lib_arch_dir != '': out_dir = '#platform/android/java/libs/' + lib_type_dir + '/' + lib_arch_dir env_android.Command(out_dir + '/libgodot_android.so', '#bin/libgodot' + env['SHLIBSUFFIX'], Move("$TARGET", "$SOURCE")) + ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"]) + if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): + stl_lib_path = str(env['ANDROID_NDK_ROOT']) + '/sources/cxx-stl/llvm-libc++/libs/' + lib_arch_dir + '/libc++_shared.so' + env_android.Command(out_dir + '/libc++_shared.so', stl_lib_path, Copy("$TARGET", "$SOURCE")) \ No newline at end of file diff --git a/platform/android/detect.py b/platform/android/detect.py index bbef3519de3..57821a226fd 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -199,12 +199,20 @@ def configure(env): ## Compile flags + if env['android_stl']: + env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/include"]) + env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++abi/include"]) + env.Append(CXXFLAGS=['-frtti',"-std=gnu++14"]) + else: + env.Append(CXXFLAGS=['-fno-rtti', '-fno-exceptions', '-DNO_SAFE_CAST']) + ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"]) if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): print("Using NDK unified headers") sysroot = env["ANDROID_NDK_ROOT"] + "/sysroot" - env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"]) + env.Append(CPPFLAGS=["--sysroot="+sysroot]) env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include/" + abi_subpath]) + env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/android/support/include"]) # For unified headers this define has to be set manually env.Append(CPPFLAGS=["-D__ANDROID_API__=" + str(get_platform(env['ndk_platform']))]) else: @@ -241,23 +249,24 @@ def configure(env): env.Append(CPPFLAGS=target_opts) env.Append(CPPFLAGS=common_opts) - if env['android_stl']: - env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/include"]) - env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath + "/include"]) - env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath]) - env.Append(LIBS=["gnustl_static"]) - else: - env.Append(CXXFLAGS=['-fno-rtti', '-fno-exceptions', '-DNO_SAFE_CAST']) - ## Link flags + if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): + if LooseVersion(ndk_version) >= LooseVersion("17.1.4828580"): + env.Append(LINKFLAGS=['-Wl,--exclude-libs,libgcc.a','-Wl,--exclude-libs,libatomic.a','-nostdlib++']) + env.Append(LINKFLAGS=['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']) + env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/"]) + env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libandroid_support.a"]) + env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libc++_shared.so"]) + else: + env.Append(LINKFLAGS=['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']) + if mt_link: + env.Append(LINKFLAGS=['-Wl,--threads']) - env['LINKFLAGS'] = ['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel'] if env["android_arch"] == "armv7": env.Append(LINKFLAGS='-Wl,--fix-cortex-a8'.split()) env.Append(LINKFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'.split()) env.Append(LINKFLAGS='-Wl,-soname,libgodot_android.so -Wl,--gc-sections'.split()) - if mt_link: - env.Append(LINKFLAGS=['-Wl,--threads']) + env.Append(LINKFLAGS=target_opts) env.Append(LINKFLAGS=common_opts) From 8c714bf8cd91e9289569f60b359dc3d3e0603411 Mon Sep 17 00:00:00 2001 From: Wojciech Milkowski Date: Tue, 28 Aug 2018 02:28:07 +0200 Subject: [PATCH 3/4] No need to link with libandroid_support in NDK 17 According to https://github.com/bytedeco/javacpp/pull/244 in NDK 17 libandroid_support library is not needed any more, and on armv8 is already gone which breaks compilation. (cherry picked from commit 3a3ea6d5147b303ee24299d4aa19e99f3131a6bd) --- platform/android/detect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/android/detect.py b/platform/android/detect.py index 57821a226fd..64fb530afbf 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -253,9 +253,10 @@ def configure(env): if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): if LooseVersion(ndk_version) >= LooseVersion("17.1.4828580"): env.Append(LINKFLAGS=['-Wl,--exclude-libs,libgcc.a','-Wl,--exclude-libs,libatomic.a','-nostdlib++']) + else: + env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libandroid_support.a"]) env.Append(LINKFLAGS=['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']) env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/"]) - env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libandroid_support.a"]) env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libc++_shared.so"]) else: env.Append(LINKFLAGS=['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']) From 74fe5968c15021edaf8e799b029feb71703744a4 Mon Sep 17 00:00:00 2001 From: Wojciech Milkowski Date: Mon, 8 Oct 2018 22:35:18 +0200 Subject: [PATCH 4/4] Fix build with Android NDK r18 As a bonus there is no need to use undocumented Gradle API any more. (cherry picked from commit 3598165c4de330abdcf93c383886e8c2d684d6cf) --- platform/android/build.gradle.template | 11 +++++++---- .../java/gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index 7269e658b45..0dd1fe815fe 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -1,10 +1,11 @@ buildscript { repositories { + google() jcenter() $$GRADLE_REPOSITORY_URLS$$ } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.2.0' $$GRADLE_CLASSPATH$$ } } @@ -33,7 +34,7 @@ android { } compileSdkVersion 27 - buildToolsVersion "27.0.3" + buildToolsVersion "28.0.3" useLibrary 'org.apache.http.legacy' packagingOptions { @@ -76,9 +77,11 @@ android { $$GRADLE_JNI_DIRS$$ ] } + applicationVariants.all { variant -> - // ApplicationVariant is undocumented, but this method is widely used; may break with another version of the Android Gradle plugin - variant.outputs.get(0).setOutputFile(new File("${projectDir}/../../../bin", "android_${variant.name}.apk")) + variant.outputs.all { output -> + output.outputFileName = "../../../../../../../bin/android_${variant.name}.apk" + } } } diff --git a/platform/android/java/gradle/wrapper/gradle-wrapper.properties b/platform/android/java/gradle/wrapper/gradle-wrapper.properties index fe37fa74a92..6fb3a795461 100644 --- a/platform/android/java/gradle/wrapper/gradle-wrapper.properties +++ b/platform/android/java/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip