Skip to content

Commit

Permalink
Increase minimum Android API level to 24 (#125946)
Browse files Browse the repository at this point in the history
Minimum Android API level has been increased to 24 (Android 7.0).
  • Loading branch information
mhsmith authored Oct 25, 2024
1 parent b08570c commit 371c537
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Android/android-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
: ${HOST:?} # GNU target triplet

# You may also override the following:
: ${api_level:=21} # Minimum Android API level the build will run on
: ${api_level:=24} # Minimum Android API level the build will run on
: ${PREFIX:-} # Path in which to find required libraries


Expand Down
14 changes: 12 additions & 2 deletions Android/testbed/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,24 @@ val PYTHON_VERSION = file("$PYTHON_DIR/Include/patchlevel.h").useLines {


android {
val androidEnvFile = file("../../android-env.sh").absoluteFile

namespace = "org.python.testbed"
compileSdk = 34

defaultConfig {
applicationId = "org.python.testbed"
minSdk = 21

minSdk = androidEnvFile.useLines {
for (line in it) {
"""api_level:=(\d+)""".toRegex().find(line)?.let {
return@useLines it.groupValues[1].toInt()
}
}
throw GradleException("Failed to find API level in $androidEnvFile")
}
targetSdk = 34

versionCode = 1
versionName = "1.0"

Expand All @@ -52,7 +63,6 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

val androidEnvFile = file("../../android-env.sh").absoluteFile
ndkVersion = androidEnvFile.useLines {
for (line in it) {
"""ndk_version=(\S+)""".toRegex().find(line)?.let {
Expand Down
9 changes: 7 additions & 2 deletions Android/testbed/app/src/main/c/main_activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ typedef struct {
int pipe[2];
} StreamInfo;

// The FILE member can't be initialized here because stdout and stderr are not
// compile-time constants. Instead, it's initialized immediately before the
// redirection.
static StreamInfo STREAMS[] = {
{stdout, STDOUT_FILENO, ANDROID_LOG_INFO, "native.stdout", {-1, -1}},
{stderr, STDERR_FILENO, ANDROID_LOG_WARN, "native.stderr", {-1, -1}},
{NULL, STDOUT_FILENO, ANDROID_LOG_INFO, "native.stdout", {-1, -1}},
{NULL, STDERR_FILENO, ANDROID_LOG_WARN, "native.stderr", {-1, -1}},
{NULL, -1, ANDROID_LOG_UNKNOWN, NULL, {-1, -1}},
};

Expand Down Expand Up @@ -87,6 +90,8 @@ static char *redirect_stream(StreamInfo *si) {
JNIEXPORT void JNICALL Java_org_python_testbed_PythonTestRunner_redirectStdioToLogcat(
JNIEnv *env, jobject obj
) {
STREAMS[0].file = stdout;
STREAMS[1].file = stderr;
for (StreamInfo *si = STREAMS; si->file; si++) {
char *error_prefix;
if ((error_prefix = redirect_stream(si))) {
Expand Down
4 changes: 0 additions & 4 deletions Lib/test/test_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@


# Test redirection of stdout and stderr to the Android log.
@unittest.skipIf(
api_level < 23 and platform.machine() == "aarch64",
"SELinux blocks reading logs on older ARM64 emulators"
)
class TestAndroidOutput(unittest.TestCase):
maxDiff = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The minimum supported Android version is now 7.0 (API level 24).

0 comments on commit 371c537

Please sign in to comment.