Skip to content

Commit 53deb85

Browse files
authored
kivy and pyjnius: switch to PyProjectRecipe (#3139)
1 parent 58d148b commit 53deb85

File tree

4 files changed

+53
-33
lines changed

4 files changed

+53
-33
lines changed

pythonforandroid/recipes/kivy/__init__.py

+14-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import glob
2-
from os.path import basename, exists, join
1+
from os.path import join
32
import sys
43
import packaging.version
54

65
import sh
7-
from pythonforandroid.recipe import CythonRecipe
6+
from pythonforandroid.recipe import PyProjectRecipe
87
from pythonforandroid.toolchain import current_directory, shprint
98

109

@@ -21,7 +20,7 @@ def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
2120
) < packaging.version.Version("2.2.0.dev0")
2221

2322

24-
class KivyRecipe(CythonRecipe):
23+
class KivyRecipe(PyProjectRecipe):
2524
version = '2.3.1'
2625
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
2726
name = 'kivy'
@@ -33,34 +32,20 @@ class KivyRecipe(CythonRecipe):
3332
# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
3433
# See: https://github.com/kivy/kivy/pull/8025
3534
# WARNING: Remove this patch when a new Kivy version is released.
36-
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]
35+
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue), "use_cython.patch"]
3736

38-
def cythonize_build(self, env, build_dir='.'):
39-
super().cythonize_build(env, build_dir=build_dir)
37+
def get_recipe_env(self, arch, **kwargs):
38+
env = super().get_recipe_env(arch, **kwargs)
4039

41-
if not exists(join(build_dir, 'kivy', 'include')):
42-
return
40+
# Taken from CythonRecipe
41+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{} '.format(
42+
self.ctx.get_libs_dir(arch.arch) +
43+
' -L{} '.format(self.ctx.libs_dir) +
44+
' -L{}'.format(join(self.ctx.bootstrap.build_dir, 'obj', 'local',
45+
arch.arch)))
46+
env['LDSHARED'] = env['CC'] + ' -shared'
47+
env['LIBLINK'] = 'NOTNONE'
4348

44-
# If kivy is new enough to use the include dir, copy it
45-
# manually to the right location as we bypass this stage of
46-
# the build
47-
with current_directory(build_dir):
48-
build_libs_dirs = glob.glob(join('build', 'lib.*'))
49-
50-
for dirn in build_libs_dirs:
51-
shprint(sh.cp, '-r', join('kivy', 'include'),
52-
join(dirn, 'kivy'))
53-
54-
def cythonize_file(self, env, build_dir, filename):
55-
# We can ignore a few files that aren't important to the
56-
# android build, and may not work on Android anyway
57-
do_not_cythonize = ['window_x11.pyx', 'camera_avfoundation.pyx', 'img_imageio.pyx', 'egl_angle_metal.pyx']
58-
if basename(filename) in do_not_cythonize:
59-
return
60-
super().cythonize_file(env, build_dir, filename)
61-
62-
def get_recipe_env(self, arch):
63-
env = super().get_recipe_env(arch)
6449
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
6550
env['NDKPLATFORM'] = "NOTNONE"
6651
if 'sdl2' in self.ctx.recipe_build_order:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- kivy-master/setup.py 2025-02-25 03:08:18.000000000 +0530
2+
+++ kivy-master.mod/setup.py 2025-03-01 13:10:24.227808612 +0530
3+
@@ -249,7 +249,7 @@
4+
# This determines whether Cython specific functionality may be used.
5+
can_use_cython = True
6+
7+
-if platform in ('ios', 'android'):
8+
+if platform in ('ios'):
9+
# NEVER use or declare cython on these platforms
10+
print('Not using cython on %s' % platform)
11+
can_use_cython = False

pythonforandroid/recipes/pyjnius/__init__.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
from pythonforandroid.recipe import CythonRecipe
1+
from pythonforandroid.recipe import PyProjectRecipe
22
from pythonforandroid.toolchain import shprint, current_directory, info
33
from pythonforandroid.patching import will_build
44
import sh
55
from os.path import join
66

77

8-
class PyjniusRecipe(CythonRecipe):
8+
class PyjniusRecipe(PyProjectRecipe):
99
version = '1.6.1'
1010
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
1111
name = 'pyjnius'
1212
depends = [('genericndkbuild', 'sdl2', 'sdl3'), 'six']
1313
site_packages_name = 'jnius'
1414

1515
patches = [
16+
"use_cython.patch",
1617
('genericndkbuild_jnienv_getter.patch', will_build('genericndkbuild')),
1718
('sdl3_jnienv_getter.patch', will_build('sdl3')),
1819
]
1920

20-
def get_recipe_env(self, arch):
21-
env = super().get_recipe_env(arch)
21+
def get_recipe_env(self, arch, **kwargs):
22+
env = super().get_recipe_env(arch, **kwargs)
23+
24+
# Taken from CythonRecipe
25+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{} '.format(
26+
self.ctx.get_libs_dir(arch.arch) +
27+
' -L{} '.format(self.ctx.libs_dir) +
28+
' -L{}'.format(join(self.ctx.bootstrap.build_dir, 'obj', 'local',
29+
arch.arch)))
30+
env['LDSHARED'] = env['CC'] + ' -shared'
31+
env['LIBLINK'] = 'NOTNONE'
32+
2233
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
2334
env['NDKPLATFORM'] = "NOTNONE"
2435
return env
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- pyjnius-1.6.1/setup.py 2023-11-05 21:07:43.000000000 +0530
2+
+++ pyjnius-1.6.1.mod/setup.py 2025-03-01 14:47:11.964847337 +0530
3+
@@ -59,10 +59,6 @@
4+
if NDKPLATFORM is not None and getenv('LIBLINK'):
5+
PLATFORM = 'android'
6+
7+
-# detect platform
8+
-if PLATFORM == 'android':
9+
- PYX_FILES = [fn[:-3] + 'c' for fn in PYX_FILES]
10+
-
11+
JAVA=get_java_setup(PLATFORM)
12+
13+
assert JAVA.is_jdk(), "You need a JDK, we only found a JRE. Try setting JAVA_HOME"

0 commit comments

Comments
 (0)