我在python-for-android中修改了opencv配方,如下所示。
import os
import sh
from pythonforandroid.recipe import NDKRecipe
from pythonforandroid.toolchain import (
current_directory,
shprint,
)
from multiprocessing import cpu_count
class OpenCVRecipe(NDKRecipe):
version = '3.4.1'
url = 'https://github.com/Itseez/opencv/archive/{version}.zip'
#md5sum = '2ddfa98e867e6611254040df841186dc'
depends = ['numpy']
#patches = ['patches/p4a_build-2.4.10.1.patch']
generated_libraries = ['cv2.so']
def prebuild_arch(self, arch):
self.apply_patches(arch)
def get_recipe_env(self, arch):
env = super(OpenCVRecipe, self).get_recipe_env(arch)
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['ANDROID_NDK'] = self.ctx.ndk_dir
env['ANDROID_SDK'] = self.ctx.sdk_dir
env['SITEPACKAGES_PATH'] = self.ctx.get_site_packages_dir()
return env
def build_arch(self, arch):
with current_directory(self.get_build_dir(arch.arch)):
env = self.get_recipe_env(arch)
cvsrc = self.get_build_dir(arch.arch)
lib_dir = os.path.join(self.ctx.get_python_install_dir(), "lib")
shprint(sh.cmake,
'-DP4A=ON', '-DANDROID_ABI={}'.format(arch.arch),
'-DCMAKE_TOOLCHAIN_FILE={}/platforms/android/android.toolchain.cmake'.format(cvsrc),
'-DPYTHON_INCLUDE_PATH={}/include/python3.6'.format(env['PYTHON_ROOT']),
'-DPYTHON_LIBRARY={}/lib/libpython3.6.so'.format(env['PYTHON_ROOT']),
'-DPYTHON_NUMPY_INCLUDE_DIR={}/numpy/core/include'.format(env['SITEPACKAGES_PATH']),
'-DANDROID_EXECUTABLE={}/tools/android'.format(env['ANDROID_SDK']),
'-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF',
'-DBUILD_EXAMPLES=OFF', '-DBUILD_ANDROID_EXAMPLES=OFF',
'-DPYTHON_PACKAGES_PATH={}'.format(env['SITEPACKAGES_PATH']),
cvsrc,
_env=env)
shprint(sh.make, '-j', str(cpu_count()), 'opencv_python')
shprint(sh.cmake, '-DCOMPONENT=python', '-P', './cmake_install.cmake')
sh.cp('-a', sh.glob('./lib/{}/lib*.so'.format(arch.arch)), lib_dir)
recipe = OpenCVRecipe()
在python-for-android构建opencv时出现错误。
sh.ErrorReturnCode_1:
RAN:/ usr / local / bin / cmake -DP4A = ON -DANDROID_ABI = armeabi-v7a -DCMAKE_TOOLCHAIN_FILE = / home / ubuntu / build / android / platform / build / build / other_builds / opencv / armeabi-v7a / opencv / platforms / android / android.toolchain.cmake -DPYTHON_INCLUDE_PATH = / home / ubuntu / build / android / platform / build / build / python-installs / simpleapp / include / python3.6 -DPYTHON_LIBRARY = / home / ubuntu / build / android / platform / build / build / python-installs / simpleapp / lib / libpython3.6.so -DPYTHON_NUMPY_INCLUDE_DIR = / home / ubuntu / build / android / platform / build / build / python-installs / simpleapp / numpy / core / include -DANDROID_EXECUTABLE = / home / ubuntu / .buildozer / android / platform / android-sdk-20 / tools / android -DBUILD_TESTS = OFF -DBUILD_PERF_TESTS = OFF -DBUILD_EXAMPLES = OFF -DBUILD_ANDROID_EXAMPLES = OFF -DPYTHON_PACK / SUN / PACKAGES_PATH = android / platform / build / build / python-installs / simpleapp / home / ubuntu / build / android / platform / build / build / other_builds / opencv / armeabi-v7a / opencv
STDOUT:CMakeLists.txt:11(消息)处的CMake错误:
致命:不允许进行源内构建。
您应该为构建文件创建一个单独的目录。
-配置不完整,发生了错误!
如何解决?