Skip to content

Commit 1702ce5

Browse files
[3.14] Minor fixes for Android (GH-154895) (#154906)
A collection of small cleanups for Android support: * Clarifies the documentation around version number handling for iOS and Android in os.uname and platform.release * Ensures that automated NDK installs surface messages written to stderr * Makes the Android NDK check more robust for incomplete downloads * Corrects some linting errors in Android build scripts (cherry picked from commit f4b1d3e) Co-authored-by: Malcolm Smith <smith@chaquo.com>
1 parent 71dfe72 commit 1702ce5

5 files changed

Lines changed: 13 additions & 14 deletions

File tree

Android/android-env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
: "${PREFIX:-}" # Path in which to find required libraries
88

99

10-
# Print all messages on stderr so they're visible when running within build-wheel.
10+
# Print all messages on stderr so they're visible when stdout is captured.
1111
log() {
1212
echo "$1" >&2
1313
}
@@ -27,7 +27,7 @@ fail() {
2727
ndk_version=27.3.13750724
2828

2929
ndk=$ANDROID_HOME/ndk/$ndk_version
30-
if ! [ -e "$ndk" ]; then
30+
if ! [ -e "$ndk/package.xml" ]; then
3131
log "Installing NDK - this may take several minutes"
3232
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
3333
fi

Android/android.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def android_env(host):
155155
f"PREFIX={prefix}; "
156156
f". {ENV_SCRIPT}; "
157157
f"export",
158-
check=True, shell=True, capture_output=True, encoding='utf-8',
158+
check=True, shell=True, stdout=subprocess.PIPE, encoding='utf-8',
159159
).stdout
160160

161161
env = {}
@@ -622,7 +622,8 @@ async def read_int(size):
622622
except ValueError:
623623
priority = LogPriority.UNKNOWN
624624

625-
payload_fields = (await read_bytes(payload_len - 1)).split(b"\0")
625+
payload = await read_bytes(payload_len - 1)
626+
payload_fields = payload.split(b"\0")
626627
if len(payload_fields) < 2:
627628
raise ValueError(
628629
f"payload {payload!r} does not contain at least 2 "

Android/testbed/app/src/main/java/org/python/testbed/MainActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ class PythonTestRunner(val context: Context) {
2828
* @param args Python command-line, encoded as JSON.
2929
* @return The Python exit status: zero on success, nonzero on failure. */
3030
fun run(args: String) : Int {
31-
// We leave argument 0 as an empty string, which is a placeholder for the
32-
// executable name in embedded mode.
31+
// Argument 0 is a placeholder for the executable name in embedded mode.
3332
val argsJsonArray = JSONArray(args)
34-
val argsStringArray = Array<String>(argsJsonArray.length() + 1) { it -> ""}
35-
for (i in 0..<argsJsonArray.length()) {
36-
argsStringArray[i + 1] = argsJsonArray.getString(i)
33+
val argsStringArray = Array<String>(argsJsonArray.length() + 1) { i ->
34+
if (i == 0) ""
35+
else argsJsonArray.getString(i - 1)
3736
}
3837

3938
// Python needs this variable to help it find the temporary directory,

Doc/library/os.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,9 @@ process and user.
793793
Returns information identifying the current operating system.
794794
The return value is a :class:`uname_result`.
795795

796-
On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
796+
On macOS, iOS and Android, this returns the *kernel* name and release (i.e.,
797797
``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
798-
can be used to get the user-facing operating system name and version on iOS and
798+
can be used to get the user-facing operating system name and release on iOS and
799799
Android.
800800

801801
.. seealso::

Doc/library/platform.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ Cross platform
144144
Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'``. An empty string is
145145
returned if the value cannot be determined.
146146

147+
On iOS and Android, this is the user-facing OS release. To obtain the
148+
Darwin or Linux kernel release, use :func:`os.uname`.
147149

148150
.. function:: system()
149151

@@ -166,9 +168,6 @@ Cross platform
166168
Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
167169
returned if the value cannot be determined.
168170

169-
On iOS and Android, this is the user-facing OS version. To obtain the
170-
Darwin or Linux kernel version, use :func:`os.uname`.
171-
172171
.. function:: uname()
173172

174173
Fairly portable uname interface. Returns a :func:`~collections.namedtuple`

0 commit comments

Comments
 (0)