From f93e9553ef8199a2283d238a7d164ad0854fdd61 Mon Sep 17 00:00:00 2001 From: lanmao Date: Thu, 30 Apr 2026 09:45:38 +0800 Subject: [PATCH 1/4] Fix tflite-runtime numpy include path --- pythonforandroid/recipes/tflite-runtime/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/recipes/tflite-runtime/__init__.py b/pythonforandroid/recipes/tflite-runtime/__init__.py index 1d208866c2..436bb26f41 100644 --- a/pythonforandroid/recipes/tflite-runtime/__init__.py +++ b/pythonforandroid/recipes/tflite-runtime/__init__.py @@ -1,7 +1,7 @@ from pythonforandroid.recipe import PythonRecipe, current_directory, \ shprint, info_main, warning from pythonforandroid.logger import error -from os.path import join +from os.path import exists, join import sh @@ -61,7 +61,10 @@ def build_arch(self, arch): pybind11_recipe = self.get_recipe('pybind11', self.ctx) pybind11_include_dir = pybind11_recipe.get_include_dir(arch) numpy_include_dir = join(self.ctx.get_site_packages_dir(arch), - 'numpy', 'core', 'include') + 'numpy', '_core', 'include') + if not exists(numpy_include_dir): + numpy_include_dir = join(self.ctx.get_site_packages_dir(arch), + 'numpy', 'core', 'include') includes = ' -I' + python_include_dir + \ ' -I' + numpy_include_dir + \ ' -I' + pybind11_include_dir From 1b0066c3193a649b19605179a9ad9fb44b34193a Mon Sep 17 00:00:00 2001 From: lanmao Date: Fri, 1 May 2026 11:55:30 +0800 Subject: [PATCH 2/4] Avoid rebuilding pybind11 for tflite-runtime --- pythonforandroid/recipes/tflite-runtime/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pythonforandroid/recipes/tflite-runtime/__init__.py b/pythonforandroid/recipes/tflite-runtime/__init__.py index 436bb26f41..456ba28761 100644 --- a/pythonforandroid/recipes/tflite-runtime/__init__.py +++ b/pythonforandroid/recipes/tflite-runtime/__init__.py @@ -25,7 +25,8 @@ class TFLiteRuntimeRecipe(PythonRecipe): version = '2.8.0' url = 'https://github.com/tensorflow/tensorflow/archive/refs/tags/v{version}.zip' - depends = ['pybind11', 'numpy'] + depends = ['numpy'] + hostpython_prerequisites = ['pybind11==2.11.1'] patches = ['CMakeLists.patch', 'build_with_cmake.patch'] site_packages_name = 'tflite-runtime' call_hostpython_via_targetpython = False @@ -49,6 +50,7 @@ def build_arch(self, arch): return env = self.get_recipe_env(arch) + self.install_hostpython_prerequisites() # Directories root_dir = self.get_build_dir(arch.arch) @@ -58,8 +60,9 @@ def build_arch(self, arch): # Includes python_include_dir = self.ctx.python_recipe.include_root(arch.arch) - pybind11_recipe = self.get_recipe('pybind11', self.ctx) - pybind11_include_dir = pybind11_recipe.get_include_dir(arch) + pybind11_include_dir = sh.Command(self.real_hostpython_location)( + '-c', 'import pybind11; print(pybind11.get_include())' + ).strip() numpy_include_dir = join(self.ctx.get_site_packages_dir(arch), 'numpy', '_core', 'include') if not exists(numpy_include_dir): From e58f7336cd72d067ec933e51d7c5e3574abcaf3a Mon Sep 17 00:00:00 2001 From: lanmao Date: Fri, 1 May 2026 12:17:13 +0800 Subject: [PATCH 3/4] Fix tflite-runtime build with CMake 4 --- .../recipes/tflite-runtime/build_with_cmake.patch | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch b/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch index 9670e1865f..e2678bef3d 100644 --- a/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch +++ b/pythonforandroid/recipes/tflite-runtime/build_with_cmake.patch @@ -18,7 +18,7 @@ # Build python interpreter_wrapper. mkdir -p "${BUILD_DIR}/cmake_build" -@@ -111,6 +111,18 @@ +@@ -111,6 +111,19 @@ -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ "${TENSORFLOW_LITE_DIR}" ;; @@ -29,6 +29,7 @@ + -DANDROID_ARM_NEON=ON \ + -DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \ + -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS}" \ ++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \ + -DANDROID_PLATFORM="${ANDROID_PLATFORM}" \ + -DANDROID_ABI="${ANDROID_ABI}" \ @@ -37,7 +38,7 @@ *) BUILD_FLAGS=${BUILD_FLAGS:-"-I${PYTHON_INCLUDE} -I${PYBIND11_INCLUDE}"} cmake \ -@@ -162,7 +174,7 @@ +@@ -162,7 +175,7 @@ ${PYTHON} setup.py bdist --plat-name=${WHEEL_PLATFORM_NAME} \ bdist_wheel --plat-name=${WHEEL_PLATFORM_NAME} else From 375c20d2d1e1a7acbb39c7fe637138924eecd454 Mon Sep 17 00:00:00 2001 From: lanmao Date: Fri, 1 May 2026 12:41:53 +0800 Subject: [PATCH 4/4] Propagate CMake policy minimum to tflite dependencies --- pythonforandroid/recipes/tflite-runtime/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pythonforandroid/recipes/tflite-runtime/__init__.py b/pythonforandroid/recipes/tflite-runtime/__init__.py index 456ba28761..952782dfb9 100644 --- a/pythonforandroid/recipes/tflite-runtime/__init__.py +++ b/pythonforandroid/recipes/tflite-runtime/__init__.py @@ -87,6 +87,7 @@ def build_arch(self, arch): 'ANDROID_ABI': arch.arch, 'WRAPPER_INCLUDES': includes, 'CMAKE_SHARED_LINKER_FLAGS': env['LDFLAGS'], + 'CMAKE_POLICY_VERSION_MINIMUM': '3.5', }) try: