From edf0fae1398d8b4e8b2daf561397cf7d3a6559be Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 23 Oct 2017 23:23:47 -0700 Subject: [PATCH] Updated Android build tools version, which bumped minimum deployment target to API 14 Also added native code to the Android gradle project, which allows using gradle or Android Studio to build the entire SDL application without a separate ndk-build step. --- android-project/app/build.gradle | 19 ++++++--- android-project/app/jni/Application.mk | 2 +- build-scripts/androidbuild.sh | 54 +++----------------------- docs/README-android.md | 22 +++-------- 4 files changed, 26 insertions(+), 71 deletions(-) diff --git a/android-project/app/build.gradle b/android-project/app/build.gradle index b670a69c88373..ed2dc7a56c5ff 100644 --- a/android-project/app/build.gradle +++ b/android-project/app/build.gradle @@ -1,14 +1,19 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.1" + compileSdkVersion 16 + buildToolsVersion "26.0.1" defaultConfig { applicationId "org.libsdl.app" - minSdkVersion 10 + minSdkVersion 14 targetSdkVersion 16 versionCode 1 versionName "1.0" + externalNativeBuild { + ndkBuild { + arguments "APP_PLATFORM=android-14" + } + } testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -19,7 +24,11 @@ android { } sourceSets.main { jniLibs.srcDir 'libs' - jni.srcDirs = [] //disable automatic ndk-build call + } + externalNativeBuild { + ndkBuild { + path 'jni/Android.mk' + } } lintOptions { abortOnError false @@ -27,7 +36,7 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) diff --git a/android-project/app/jni/Application.mk b/android-project/app/jni/Application.mk index 70bcf0c247e7b..b6dc19525702c 100644 --- a/android-project/app/jni/Application.mk +++ b/android-project/app/jni/Application.mk @@ -6,4 +6,4 @@ APP_ABI := all # Min SDK level -APP_PLATFORM=android-10 +APP_PLATFORM=android-14 diff --git a/build-scripts/androidbuild.sh b/build-scripts/androidbuild.sh index 916831cce8d12..814578182432c 100755 --- a/build-scripts/androidbuild.sh +++ b/build-scripts/androidbuild.sh @@ -25,12 +25,9 @@ if [ -z "$1" ] || [ -z "$SOURCES" ]; then echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list" echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c" echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... " - echo "You can pass additional arguments to ndk-build with the NDKARGS variable: NDKARGS=\"-s\" androidbuild.sh ..." exit 1 fi - - SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )" if [ -z "$ANDROID_HOME" ];then @@ -38,34 +35,11 @@ if [ -z "$ANDROID_HOME" ];then exit 1 fi -NDKBUILD=`which ndk-build` -if [ -z "$NDKBUILD" ];then - echo "Could not find the ndk-build utility, install Android's NDK and add it to the path" +if [ ! -d "$ANDROID_HOME/ndk-bundle" -a -z "$ANDROID_NDK_HOME" ]; then + echo "Please set the ANDROID_NDK_HOME directory to the path of the Android NDK" exit 1 fi -ANDROID="$ANDROID_HOME/tools/android" -if [ ! -f "$ANDROID" ]; then - ANDROID=`which android` -fi -if [ -z "$ANDROID" ];then - echo "Could not find the android utility, install Android's SDK and add it to the path" - exit 1 -fi - -NCPUS="1" -case "$OSTYPE" in - darwin*) - NCPU=`sysctl -n hw.ncpu` - ;; - linux*) - if [ -n `which nproc` ]; then - NCPUS=`nproc` - fi - ;; - *);; -esac - APP="$1" APPARR=(${APP//./ }) BUILDPATH="$SDLPATH/build/$APP" @@ -121,24 +95,6 @@ public class $ACTIVITY extends SDLActivity __EOF__ # Update project and build -cd $BUILDPATH -pushd $BUILDPATH/app/jni -$NDKBUILD -j $NCPUS $NDKARGS -popd - -# Start gradle build -$BUILDPATH/gradlew build - -cd $CURDIR - -APK="$BUILDPATH/app/build/outputs/apk/app-debug.apk" - -if [ -f "$APK" ]; then - echo "Your APK is ready at $APK" - echo "To install to your device: " - echo "$ANDROID_HOME/platform-tools/adb install -r $APK" - exit 0 -fi - -echo "There was an error building the APK" -exit 1 +echo "To build and install to a device for testing, run the following:" +echo "cd $BUILDPATH" +echo "./gradlew installDebug" diff --git a/docs/README-android.md b/docs/README-android.md index 1bf4dfd9fcd4a..87cff3ff3ad46 100644 --- a/docs/README-android.md +++ b/docs/README-android.md @@ -14,11 +14,10 @@ The rest of this README covers the traditional style build process. Android SDK (version 16 or later) https://developer.android.com/sdk/index.html -Android NDK r7 or later +Android NDK r10e or later https://developer.android.com/tools/sdk/ndk/index.html -Minimum API level supported by SDL: 10 (Android 2.3.3) -Joystick support is available for API level >= 12 devices. +Minimum API level supported by SDL: 14 (Android 4.0.1) ================================================================================ @@ -393,22 +392,13 @@ https://developer.nvidia.com/tegra-graphics-debugger ================================================================================ - Why is API level 10 the minimum required? + Why is API level 14 the minimum required? ================================================================================ -API level 10 is the minimum required level at runtime (that is, on the device) -because SDL requires some functionality for running not -available on older devices. Since the incorporation of joystick support into SDL, -the minimum SDK required to *build* SDL is version 16. Devices running API levels -10-11 are still supported, only with the joystick functionality disabled. - -Support for native OpenGL ES and ES2 applications was introduced in the NDK for -API level 4 and 8. EGL was made a stable API in the NDK for API level 9, which -has since then been obsoleted, with the recommendation to developers to bump the -required API level to 10. +The latest NDK toolchain doesn't support targeting earlier than API level 14. As of this writing, according to https://developer.android.com/about/dashboards/index.html -about 90% of the Android devices accessing Google Play support API level 10 or -higher (March 2013). +about 99% of the Android devices accessing Google Play support API level 14 or +higher (October 2017). ================================================================================