Skip to content

Commit 1130062

Browse files
committed
add Skia recipe for Kivy 3.0.0.dev0
1 parent 5330267 commit 1130062

2 files changed

Lines changed: 116 additions & 3 deletions

File tree

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
2121

2222

2323
class KivyRecipe(PyProjectRecipe):
24-
version = '2.3.1'
25-
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
24+
25+
version = '3.0.0.dev0'
26+
url = 'https://github.com/DexerBR/kivy/archive/refs/heads/skia-graphics-backend.zip'
2627
name = 'kivy'
2728

28-
depends = [('sdl2', 'sdl3'), 'pyjnius', 'setuptools']
29+
depends = [('sdl2', 'sdl3'), 'pyjnius', 'setuptools', 'skia']
2930
python_depends = ['certifi', 'chardet', 'idna', 'requests', 'urllib3', 'filetype']
3031
hostpython_prerequisites = []
3132

@@ -71,6 +72,7 @@ def get_recipe_env(self, arch, **kwargs):
7172
sdl3_image_recipe = self.get_recipe("sdl3_image", self.ctx)
7273
sdl3_ttf_recipe = self.get_recipe("sdl3_ttf", self.ctx)
7374
sdl3_recipe = self.get_recipe("sdl3", self.ctx)
75+
skia_recipe = self.get_recipe("skia", self.ctx)
7476
env["USE_SDL3"] = "1"
7577
env["KIVY_SPLIT_EXAMPLES"] = "1"
7678
env["KIVY_SDL3_PATH"] = ":".join(
@@ -81,6 +83,7 @@ def get_recipe_env(self, arch, **kwargs):
8183
*sdl3_recipe.get_include_dirs(arch),
8284
]
8385
)
86+
env["SKIA_ROOT"] = skia_recipe.get_lib_dir(arch)
8487

8588
return env
8689

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import sys
2+
import os
3+
import shutil
4+
from os.path import join, exists, basename
5+
import sh
6+
from pythonforandroid.recipe import Recipe
7+
from pythonforandroid.toolchain import shprint, current_directory
8+
from pythonforandroid.util import ensure_dir
9+
10+
11+
class SkiaRecipe(Recipe):
12+
version = "skia-binaries-m140-rev1.a0"
13+
url = "https://github.com/DexerBR/skia-builder/releases/download/{version}/android-merged.tar.gz"
14+
name = "skia"
15+
16+
skia_libraries = [
17+
"libskparagraph.a",
18+
"libskia.a",
19+
"libskottie.a",
20+
"libsksg.a",
21+
"libskshaper.a",
22+
"libskunicode_icu.a",
23+
"libskunicode_core.a",
24+
"libjsonreader.a",
25+
]
26+
27+
built_libraries = {"libskmerged.a": "bin"}
28+
29+
def _get_skia_platform(self, arch):
30+
arch_map = {
31+
"arm64-v8a": "android-arm64",
32+
"armeabi-v7a": "android-arm",
33+
"x86_64": "android-x64",
34+
"x86": "android-x86",
35+
}
36+
arch_name = arch.arch if hasattr(arch, "arch") else arch
37+
return arch_map.get(arch_name, arch_name)
38+
39+
def unpack(self, arch):
40+
build_dir = self.get_build_container_dir(arch)
41+
target_dir = self.get_build_dir(arch)
42+
43+
if exists(target_dir):
44+
return
45+
46+
ensure_dir(build_dir)
47+
48+
filename = basename(self.versioned_url)
49+
archive_path = join(self.ctx.packages_path, self.name, filename)
50+
skia_platform = self._get_skia_platform(arch)
51+
52+
with current_directory(build_dir):
53+
temp_extract_dir = join(build_dir, "temp_extract")
54+
ensure_dir(temp_extract_dir)
55+
56+
with current_directory(temp_extract_dir):
57+
shprint(sh.tar, "xzf", archive_path)
58+
59+
ensure_dir(target_dir)
60+
61+
# Find and extract the architecture-specific tar.gz
62+
arch_file = f"{skia_platform}.tar.gz"
63+
arch_file_path = join(temp_extract_dir, arch_file)
64+
65+
if exists(arch_file_path):
66+
print(f"Found {arch_file}, extracting...")
67+
with current_directory(target_dir):
68+
shprint(sh.tar, "xzf", arch_file_path)
69+
else:
70+
print(f"Architecture file not found: {arch_file}")
71+
print(f"Available files: {os.listdir(temp_extract_dir)}")
72+
sys.exit(1)
73+
74+
shutil.rmtree(temp_extract_dir)
75+
76+
def build_arch(self, arch):
77+
build_dir = self.get_build_dir(arch.arch)
78+
merged_lib_path = join(build_dir, "bin", "libskmerged.a")
79+
80+
lib_files = []
81+
for lib in self.skia_libraries:
82+
lib_path = join(build_dir, "bin", lib)
83+
if exists(lib_path):
84+
lib_files.append(lib_path)
85+
86+
if lib_files:
87+
with current_directory(build_dir):
88+
shprint(
89+
sh.Command(self.ctx.ndk.llvm_ar),
90+
"rcs",
91+
merged_lib_path,
92+
*lib_files,
93+
)
94+
95+
def get_include_dirs(self, arch):
96+
build_dir = self.get_build_dir(arch.arch)
97+
return [
98+
d
99+
for d in [
100+
join(build_dir, subdir)
101+
for subdir in ["include", "modules", "src"]
102+
]
103+
if exists(d)
104+
]
105+
106+
def get_lib_dir(self, arch):
107+
return self.get_build_dir(arch.arch)
108+
109+
110+
recipe = SkiaRecipe()

0 commit comments

Comments
 (0)