Skip to content

Commit

Permalink
Updated to Android minSdkVersion 19 and targetSdkVersion 34
Browse files Browse the repository at this point in the history
This is updated to meet the latest requirements for apps on the Google Play store
  • Loading branch information
slouken committed Aug 24, 2023
1 parent 8924d0d commit 1e9d314
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
20 changes: 10 additions & 10 deletions android-project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ else {
}

android {
compileSdkVersion 31
if (buildAsApplication) {
namespace "org.libsdl.app"
}
compileSdkVersion 34
defaultConfig {
if (buildAsApplication) {
applicationId "org.libsdl.app"
}
minSdkVersion 16
targetSdkVersion 31
minSdkVersion 19
targetSdkVersion 34
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-16"
arguments "APP_PLATFORM=android-19"
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a'
}
cmake {
arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
arguments "-DANDROID_APP_PLATFORM=android-19", "-DANDROID_STL=c++_static"
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a'
}
Expand Down Expand Up @@ -54,10 +54,10 @@ android {
}

}
lintOptions {
lint {
abortOnError false
}

if (buildAsLibrary) {
libraryVariants.all { variant ->
variant.outputs.each { output ->
Expand Down
1 change: 0 additions & 1 deletion android-project/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
com.gamemaker.game
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.libsdl.app"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
Expand Down
2 changes: 1 addition & 1 deletion android-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:8.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion android-project/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Nov 11 18:20:34 PST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
14 changes: 7 additions & 7 deletions docs/README-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ The rest of this README covers the Android gradle style build process.
Requirements
================================================================================

Android SDK (version 31 or later)
Android SDK (version 34 or later)
https://developer.android.com/sdk/index.html

Android NDK r15c or later
https://developer.android.com/tools/sdk/ndk/index.html

Minimum API level supported by SDL: 16 (Android 4.1)
Minimum API level supported by SDL: 19 (Android 4.4)


How the port works
Expand Down Expand Up @@ -435,13 +435,13 @@ The Tegra Graphics Debugger is available from NVidia here:
https://developer.nvidia.com/tegra-graphics-debugger


Why is API level 16 the minimum required?
Why is API level 19 the minimum required?
================================================================================

The latest NDK toolchain doesn't support targeting earlier than API level 16.
As of this writing, according to https://developer.android.com/about/dashboards/index.html
about 99% of the Android devices accessing Google Play support API level 16 or
higher (January 2018).
The latest NDK toolchain doesn't support targeting earlier than API level 19.
As of this writing, according to https://www.composables.com/tools/distribution-chart
about 99.7% of the Android devices accessing Google Play support API level 19 or
higher (August 2023).


A note regarding the use of the "dirty rectangles" rendering technique
Expand Down

11 comments on commit 1e9d314

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to change the minSdkVersion? I managed to targetSdkVersion 33 so far and keep minSdkVersion 16.

@slouken
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the math.h error when trying to do that... ?

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me dig deeper and attempt to target 34 again - I had some problems, but not relating to math.h.

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slouken I can confirm that I can target 34 and retain min 16. No problems at all. Slightly different build config to android-project though. Would you like me to come up with a working android-project that keeps min 16? I'm using a lot of extra stuff in project gradle.properties such as "android.useAndroidX=true" and full R8 optimization with progaurd, so I'm not sure if that is coming into play 🤷🏼‍♂️

@slouken
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Is there a simple solution for the math.h compile error? Did you run into that and solve it somehow?

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got no math.h compile error when changing the target to 34 and updating the Gradle version. I do vaguely remember a problem with math.h 1-2 years ago which had something to do with a buggy version of NDK. Android Studio seems to resolve problems after a clean and a refresh of the SDK manager.

Let me experiment some more and see if I can re-create the math.h issue with android-project and bisect what fixes it. I'm pretty sure we can keep the old minSdkVersion without doing anything complicated.

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slouken I can confirm 100% we can still have minSdkVersion 16. I took the android-project and just changed minSdkVersion 19 to minSdkVersion 16 and it works. I tried as hard as I could to reproduce any kind of compiler error and couldn't.

I have a feeling it's because of a redundant / depreciated tool that needs to be "unticked" in the SDK manager, or something needs to be cleaned. Untick all platforms and tools in SDK manager (make sure you don't hide obsolete packages). Clean Project. Refresh Linked C++ Projects. Delete ".gradle" & "build" directories. Let synch & build download the required platforms & tools. Builds no problem in Android Studio Giraffe | 2022.3.1 Patch 1.

@slouken
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you building for 32-bit arm?

I'm using the latest NDK toolchain, and this is the error I'm getting:

  C++ build system [build] failed while executing:
      /Users/valve/Library/Android/sdk/ndk/25.2.9519653/ndk-build \
        NDK_PROJECT_PATH=null \
        APP_BUILD_SCRIPT=/Users/valve/projects/SDL/build/org.libsdl.checkkeys/app/jni/Android.mk \
        NDK_APPLICATION_MK=/Users/valve/projects/SDL/build/org.libsdl.checkkeys/app/jni/Application.mk \
        APP_ABI=armeabi-v7a \
        NDK_ALL_ABIS=armeabi-v7a \
        NDK_DEBUG=1 \
        NDK_OUT=/Users/valve/projects/SDL/build/org.libsdl.checkkeys/app/build/intermediates/cxx/Debug/326x253l/obj \
        NDK_LIBS_OUT=/Users/valve/projects/SDL/build/org.libsdl.checkkeys/app/build/intermediates/cxx/Debug/326x253l/lib \
        APP_PLATFORM=android-16 \
        SDL3 \
        main
    from /Users/valve/projects/SDL/build/org.libsdl.checkkeys/app
  fcntl(): Bad file descriptor
  In file included from /Users/valve/projects/SDL/build/org.libsdl.checkkeys/app/jni/SDL/src/hidapi/android/hid.cpp:21:
  In file included from /Users/valve/projects/SDL/build/org.libsdl.checkkeys/app/jni/SDL/src/SDL_internal.h:79:
  In file included from /Users/valve/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/stdlib.h:100:
  /Users/valve/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/math.h:1377:93: error: no member named 'log2f' in the global namespace
  inline _LIBCPP_INLINE_VISIBILITY float       log2(float __lcpp_x) _NOEXCEPT       {return ::log2f(__lcpp_x);}
                                                                                            ~~^
  /Users/valve/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/math.h:1378:93: error: no member named 'log2l' in the global namespace

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can build for all the ABIs: 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'.

My build chooses 25.1.8937393, for some reason, so I added ndkVersion "25.2.9519653" and it still works. I was sure that math.h errors I had in the past were due to a bug in a specific NDK version.

There's clearly a difference between our builds, even though I created a fresh project from android-project. I don't think I'm touching cmake, if that means anything? Aren't there two different compiler options in Android? Maybe cmake chooses the other one? It could be something specific to the cmake settings, but I don't know anything about it - I just build from Android Studio's menus.

@slouken
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My build also chooses 25.1.8937393, I just forced the latest NDK just to make sure I wasn't missing anything. I'm not using cmake, just ndk-build from gradle.

Are you building hidapi/android/hid.cpp, with HIDAPI enabled?

@AntTheAlchemist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dumb-checked hid.cpp is enabled by entering gibberish in hid_init() and it failed at my gibberish. I can build debug and non-debug apk and aab of all 4 ABIs. Latest SDL source and android-project out of the box just works with min 16. FWWI, on discourse it looks like others have had it fail and others have also had it build no problem.

Let's not waste more time on this. A jump from 4.1 to 4.4 is not the end of the world. If Google plan on enforcing 4.4 minimum anyway, then it's not worth fighting this. Leave the SDL project at 19 and see if anyone else complains. If anyone can get 16 to work and wants to, then let them, maybe at least put a note in somewhere that 16 might work.

Please sign in to comment.