Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions pythonforandroid/recipes/kivy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import glob
from os.path import basename, exists, join
from os.path import join
import sys
import packaging.version

import sh
from pythonforandroid.recipe import CythonRecipe
from pythonforandroid.recipe import PyProjectRecipe
from pythonforandroid.toolchain import current_directory, shprint


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


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

def cythonize_build(self, env, build_dir='.'):
super().cythonize_build(env, build_dir=build_dir)
def get_recipe_env(self, arch, **kwargs):
env = super().get_recipe_env(arch, **kwargs)

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

# If kivy is new enough to use the include dir, copy it
# manually to the right location as we bypass this stage of
# the build
with current_directory(build_dir):
build_libs_dirs = glob.glob(join('build', 'lib.*'))

for dirn in build_libs_dirs:
shprint(sh.cp, '-r', join('kivy', 'include'),
join(dirn, 'kivy'))

def cythonize_file(self, env, build_dir, filename):
# We can ignore a few files that aren't important to the
# android build, and may not work on Android anyway
do_not_cythonize = ['window_x11.pyx', 'camera_avfoundation.pyx', 'img_imageio.pyx', 'egl_angle_metal.pyx']
if basename(filename) in do_not_cythonize:
return
super().cythonize_file(env, build_dir, filename)

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
env['NDKPLATFORM'] = "NOTNONE"
if 'sdl2' in self.ctx.recipe_build_order:
Expand Down
11 changes: 11 additions & 0 deletions pythonforandroid/recipes/kivy/use_cython.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- kivy-master/setup.py 2025-02-25 03:08:18.000000000 +0530
+++ kivy-master.mod/setup.py 2025-03-01 13:10:24.227808612 +0530
@@ -249,7 +249,7 @@
# This determines whether Cython specific functionality may be used.
can_use_cython = True

-if platform in ('ios', 'android'):
+if platform in ('ios'):
# NEVER use or declare cython on these platforms
print('Not using cython on %s' % platform)
can_use_cython = False
19 changes: 15 additions & 4 deletions pythonforandroid/recipes/pyjnius/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
from pythonforandroid.recipe import CythonRecipe
from pythonforandroid.recipe import PyProjectRecipe
from pythonforandroid.toolchain import shprint, current_directory, info
from pythonforandroid.patching import will_build
import sh
from os.path import join


class PyjniusRecipe(CythonRecipe):
class PyjniusRecipe(PyProjectRecipe):
version = '1.6.1'
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
name = 'pyjnius'
depends = [('genericndkbuild', 'sdl2', 'sdl3'), 'six']
site_packages_name = 'jnius'

patches = [
"use_cython.patch",
('genericndkbuild_jnienv_getter.patch', will_build('genericndkbuild')),
('sdl3_jnienv_getter.patch', will_build('sdl3')),
]

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
def get_recipe_env(self, arch, **kwargs):
env = super().get_recipe_env(arch, **kwargs)

# Taken from CythonRecipe
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{} '.format(
self.ctx.get_libs_dir(arch.arch) +
' -L{} '.format(self.ctx.libs_dir) +
' -L{}'.format(join(self.ctx.bootstrap.build_dir, 'obj', 'local',
arch.arch)))
env['LDSHARED'] = env['CC'] + ' -shared'
env['LIBLINK'] = 'NOTNONE'

# NDKPLATFORM is our switch for detecting Android platform, so can't be None
env['NDKPLATFORM'] = "NOTNONE"
return env
Expand Down
13 changes: 13 additions & 0 deletions pythonforandroid/recipes/pyjnius/use_cython.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- pyjnius-1.6.1/setup.py 2023-11-05 21:07:43.000000000 +0530
+++ pyjnius-1.6.1.mod/setup.py 2025-03-01 14:47:11.964847337 +0530
@@ -59,10 +59,6 @@
if NDKPLATFORM is not None and getenv('LIBLINK'):
PLATFORM = 'android'

-# detect platform
-if PLATFORM == 'android':
- PYX_FILES = [fn[:-3] + 'c' for fn in PYX_FILES]
-
JAVA=get_java_setup(PLATFORM)

assert JAVA.is_jdk(), "You need a JDK, we only found a JRE. Try setting JAVA_HOME"