Skip to content

Commit a9b902b

Browse files
Fixed Python version support. (#3283)
* Fixed a bug with Python version selection and library loading. * Fixed Python version support. * Remove conditional build argument for Python version >= 11 * Increased the minimum python version to 3.8 * Ensure patches and configure arguments are unique.
1 parent 0635bc1 commit a9b902b

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ protected static ArrayList<String> getLibraries(File libsDir) {
5959
addLibraryIfExists(libsList, name, libsDir);
6060
}
6161

62-
for (int v = 14; v >= 5; v--) {
63-
libsList.add("python3." + v + (v <= 7 ? "m" : ""));
62+
for (int v = 14; v >= 8; v--) {
63+
libsList.add("python3." + v);
6464
}
6565

6666
libsList.add("main");
@@ -85,7 +85,7 @@ public static void loadLibraries(File filesDir, File libsDir) {
8585
// load, and it has failed, give a more
8686
// general error
8787
Log.v(TAG, "Library loading error: " + e.getMessage());
88-
if (lib.startsWith("python3.14") && !foundPython) {
88+
if (lib.startsWith("python3.8") && !foundPython) {
8989
throw new RuntimeException("Could not load any libpythonXXX.so");
9090
} else if (lib.startsWith("python")) {
9191
continue;

pythonforandroid/recipes/python3/__init__.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class Python3Recipe(TargetPythonRecipe):
5555
'''
5656

5757
version = '3.14.2'
58-
_p_version = Version(version)
5958
url = 'https://github.com/python/cpython/archive/refs/tags/v{version}.tar.gz'
6059
name = 'python3'
6160

@@ -64,28 +63,6 @@ class Python3Recipe(TargetPythonRecipe):
6463
'patches/reproducible-buildinfo.diff',
6564
]
6665

67-
if _p_version.major == 3 and _p_version.minor == 7:
68-
patches += [
69-
'patches/py3.7.1_fix-ctypes-util-find-library.patch',
70-
'patches/py3.7.1_fix-zlib-version.patch',
71-
]
72-
73-
if 8 <= _p_version.minor <= 10:
74-
patches.append('patches/py3.8.1.patch')
75-
76-
if _p_version.minor >= 11:
77-
patches.append('patches/cpython-311-ctypes-find-library.patch')
78-
79-
if _p_version.minor >= 14:
80-
patches.append('patches/3.14_armv7l_fix.patch')
81-
patches.append('patches/3.14_fix_remote_debug.patch')
82-
83-
if shutil.which('lld') is not None:
84-
if _p_version.minor == 7:
85-
patches.append("patches/py3.7.1_fix_cortex_a8.patch")
86-
elif _p_version.minor >= 8:
87-
patches.append("patches/py3.8.1_fix_cortex_a8.patch")
88-
8966
depends = ['hostpython3', 'sqlite3', 'openssl', 'libffi']
9067
# those optional depends allow us to build python compression modules:
9168
# - _bz2.so
@@ -116,11 +93,6 @@ class Python3Recipe(TargetPythonRecipe):
11693
'ac_cv_header_bzlib_h=no',
11794
]
11895

119-
if _p_version.minor >= 11:
120-
configure_args.extend([
121-
'--with-build-python={python_host_bin}',
122-
])
123-
12496
'''The configure arguments needed to build the python recipe. Those are
12597
used in method :meth:`build_arch` (if not overwritten like python3's
12698
recipe does).
@@ -210,6 +182,34 @@ def link_version(self):
210182
flags=flags
211183
)
212184

185+
def apply_patches(self, arch, build_dir=None):
186+
187+
_p_version = Version(self.version)
188+
if _p_version.major == 3 and _p_version.minor == 7:
189+
self.patches += [
190+
'patches/py3.7.1_fix-ctypes-util-find-library.patch',
191+
'patches/py3.7.1_fix-zlib-version.patch',
192+
]
193+
194+
if 8 <= _p_version.minor <= 10:
195+
self.patches.append('patches/py3.8.1.patch')
196+
197+
if _p_version.minor >= 11:
198+
self.patches.append('patches/cpython-311-ctypes-find-library.patch')
199+
200+
if _p_version.minor >= 14:
201+
self.patches.append('patches/3.14_armv7l_fix.patch')
202+
self.patches.append('patches/3.14_fix_remote_debug.patch')
203+
204+
if shutil.which('lld') is not None:
205+
if _p_version.minor == 7:
206+
self.patches.append("patches/py3.7.1_fix_cortex_a8.patch")
207+
elif _p_version.minor >= 8:
208+
self.patches.append("patches/py3.8.1_fix_cortex_a8.patch")
209+
210+
self.patches = list(set(self.patches))
211+
super().apply_patches(arch, build_dir)
212+
213213
def include_root(self, arch_name):
214214
return join(self.get_build_dir(arch_name), 'Include')
215215

@@ -317,9 +317,15 @@ def add_flags(include_flags, link_dirs, link_libs):
317317
env['ZLIB_VERSION'] = line.replace('#define ZLIB_VERSION ', '')
318318
add_flags(' -I' + zlib_includes, ' -L' + zlib_lib_path, ' -lz')
319319

320-
if self._p_version.minor >= 13 and self.disable_gil:
320+
_p_version = Version(self.version)
321+
if _p_version.minor >= 11:
322+
self.configure_args.append('--with-build-python={python_host_bin}')
323+
324+
if _p_version.minor >= 13 and self.disable_gil:
321325
self.configure_args.append("--disable-gil")
322326

327+
self.configure_args = list(set(self.configure_args))
328+
323329
return env
324330

325331
def build_arch(self, arch):

0 commit comments

Comments
 (0)