问题描述
我正在尝试使用 kivy、opencv 创建一个简单的照片捕捉应用程序.当我尝试使用 buildozer 创建一个 .apk 文件,并将 opencv 放在 .spec 文件的要求中时,我遇到了这个错误
I'm trying to create a simple photo capture app using kivy, opencv. When I tried to create an .apk file using buildozer, and put opencv in requirements at .spec file then I faced this error
-- Android: fixup -g compiler option from Android toolchain
-- Update variable ANDROID_SDK from environment: /home/livon/.buildozer/android/platform/android-sdk
-- Android SDK Tools: ver. 2.0 (description: 'Android SDK Command-line Tools')
-- Android SDK Build Tools: ver. 30.0.0 (subdir 30.0.0 from 30.0.0)
CMake Error at cmake/android/OpenCVDetectAndroidSDK.cmake:176 (message):
Android SDK Tools: OpenCV requires Android SDK Tools revision 14 or newer.
Use BUILD_ANDROID_PROJECTS=OFF to prepare Android project files without
building them
Call Stack (most recent call first):
CMakeLists.txt:780 (include)
-- Configuring incomplete, errors occurred!
See also "/home/livon/Desktop/Ocv/.buildozer/android/platform/build-armeabi-
v7a/build/other_builds/opencv/armeabi-v7a__ndk_target_21/opencv/build/CMakeFiles/CMakeOutput.log".
See also "/home/livon/Desktop/Ocv/.buildozer/android/platform/build-armeabi-
v7a/build/other_builds/opencv/armeabi-v7a__ndk_target_21/opencv/build/CMakeFiles/CMakeError.log".er
# Command failed: /home/livon/venv/bin/python3 -m pythonforandroid.toolchain create --dist_name=test
--bootstrap=sdl2 --requirements=python3,kivy,opencv --arch armeabi-v7a --copy-libs --color=always --
storage-dir="/home/livon/Desktop/Ocv/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21
# ENVIRONMENT:
# ANDROIDNDK = '/home/livon/.buildozer/android/platform/android-ndk-r19c'
# ANDROIDAPI = '27'
# ANDROIDMINAPI = '21'
我也尝试过更新 ANDROID_SDK,我去了 (/home/livon/.buildozer/android/platform/android-sdk) 这个文件夹并使用更新它
I have also tried to update ANDROID_SDK, I went to (/home/livon/.buildozer/android/platform/android-sdk) this folder and updated it using
sudo apt-get upgrade
但更新到 30.0.0 后没有任何变化,错误依旧.
But after updated it to 30.0.0 nothing has changed, the error remain same.
我正在使用
- Ubuntu 19.10
- Python 3.7.5
- 基维 1.11.1
- Buildozer 1.2.0
- openCv 4
推荐答案
我也遇到这个错误,烦了好久:(
I get this error too and fretted for a long time : (
经过一堆谷歌搜索,我找到了一些可能有帮助的解决方案.
After a bunch of google searches, I found some solutions that may help.
至少它可以在我的 Ubuntu 20.04 VM 上运行.
At least it works on my Ubuntu 20.04 VM.
(下载 Android Studio 并复制粘贴 dir 部分(最后 3 步)的说明可能会解决您的问题,因为我也遇到了与您相同的错误)
( The instruction to download Android Studio and copy-paste the dir part (last 3 steps) may solve your problem , as I also got the same error as you )
先更新
apt
sudo apt-get update
升级包
upgrade pkgs
sudo apt-get upgrade
安装python3 + pip
install python3 + pip
sudo apt-get install python3 python3-pip
配置默认 Python 版本(ref_1 ) ( ref_2 )
sudo update-alternatives --install /usr/bin/python python /usr/bin/python<X.X.X> 1
sudo update-alternatives --config python
其中 <X.X.X>
是所需的 Python 版本.
where <X.X.X>
is the desired Python ver.
安装开发工具+依赖项
sudo apt-get install build-essential
libssl-dev
libffi-dev
python3-dev
dh-autoreconf
autoconf
libtool
pkg-config
zlib1g-dev
libncurses5-dev
libncursesw5-dev
libtinfo5
cmake
ccache
安装 kivy
install kivy
通过
apt
sudo apt-get install python3-kivy
通过 Python pip(我的首选方式)
through Python pip ( my preferred way )
python3 -m pip install kivy==2.0.0
安装 cython
pip3 install Cython
sudo apt-get install cython
//我是这样做的
安装javac
sudo apt-get install openjdk-11-jdk openjdk-8-jdk
检查是否安装了java
和javac
java -version
javac -version
配置.java
+ javac
(我将它配置为 openjdk8-jdk
)
config. java
+ javac
( I config. it to openjdk8-jdk
)
sudo update-alternatives --config java
sudo update-alternatives --config javac
安装cmake
(我都做了)(参考 )
蟒蛇方式
python way
pip3 install cmake
手动方式
manual way
cd /tmp
wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0.tar.gz
tar -zxvf cmake-3.20.0.tar.gz
cd cmake-3.20.0
./bootstrap
make
sudo make install
安装 buildozer(我用 官方方式重新安装了)
install buildozer ( I reinstalled it using the official way )
官方方式
official way
pip3 install --user --upgrade buildozer
通过 git clone
through git clone
sudo apt-get install git
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python3 setup.py install
安装Python IDLE(可选)(以下任意一种)
install Python IDLE ( optional ) ( either one of the following )
sudo apt-get install idle3
安装 Android Studio
install Android Studio
我尝试了不安装 Android Studio 的方法(仅使用 cmdline-tools),但就是想不通:(
I tried the way not to install Android Studio ( using cmdline-tools only ), but just can't figure it out : (
sudo snap install android-studio --classic
然后运行它,让它自己设置一切.
and run it and let it set up everything by itself.
然后,关闭它
一切设置完成后:(ref)
打开文件
复制 ~/Home/Android/Sdk/中的
tools
目录
copy the tools
dir located in ~/Home/Android/Sdk/
将其粘贴到 ~/Home/.buildozer/android/platform/android-sdk
压缩位于那里的原始 tools
目录(通过右键单击 --> compress )(如果看不到目录,请确保选中文件选项中的 show hidden file
复选框)
paste it at ~/Home/.buildozer/android/platform/android-sdk
after compressing the original tools
dir located there ( by right click --> compress ) ( if you can't see the dir, make sure to check the show hidden file
checkbox in the file's option )
然后转到~/Home/.buildozer/android/platform/android-sdk/tools/bin
并在终端打开
./sdkmanager --install "tools"
exit
再次重建项目转到您项目的目录
rebuild the project againgo to your project's dir
buildozer init # if you haven't got the buildozer.spec in your project's dir
buildozer android debug
*.apk
将在 bin
我的 buildozer.spec
:
title = Screen_Recorder
package.name = screen_recorder
package.domain = org.test
souce.dir = .
source.include_exts = py,png,jpg,kv,atlas
requirements = python3,kivy==2.0.0,android,opencv==4.5.3,numpy,pillow,EasyProcess,entrypoint2,mss,jeepney,plyer,pyscreenshot
osx.python_version = 3
osx.kivy_version = 2.0.0
android.permission = CAMERA,RECORD_AUDIO,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE
参考
- Stackoverflow 问题:kivy camera application with opencv inandroid显示黑屏
- Stackoverflow 问题:启动时生成的日志Android 上 Kivy Launcher 中的应用
- Stackoverflow 问题:我无法为 android 构建 buildozer
- Youtube 视频(我按照此视频(复制粘贴目录部分)使其工作): 让 opencv4 在 ubuntu 上与 kivy/buildozer 一起工作
- git 讨论:Android 编译因 opencv 失败
- Stackoverflow 问题:android 权限在 python 中使用 request_permissions李>
- python-for-android 文档 - 在 Android 上工作
- 如果您对根目录进行了更改,请关闭终端并重新打开它
- 不要编辑
.bashrc
文件(在我的情况下,我没有) - 每次重建项目时删除项目目录中的
bin
和.buildozer
目录或运行buildozer <platform>干净
- 使用
ls
列出当前目录下的所有文件+文件夹 - 使用
cd <dir>
导航到目录 - 使用
cd ..
导航到上一个目录 - 如果您需要像
CAMERA
这样的权限,则需要将其添加到buildozer.spec
的permission
并在您的*.py
获得android 权限: - close the terminal and reopen it if you make changes to the root dir
- don't edit the
.bashrc
file ( in my case, I didn't ) - delete the
bin
and.buildozer
dir in your project's dir every time you rebuild your project OR runbuildozer <platform> clean
- use
ls
to list all files + folders in the current dir - use
cd <dir>
to navigate to directory - use
cd ..
to navigate to the previous dir - if you need permission like
CAMERA
, you need to add it to thebuildozer.spec
'spermission
and add the following in your*.py
to gain android permission:
from kivy.utils import platform
if platform == "android":
from android.permissions import request_permissions, Permission
request_permissions([ <permissions> ]) # e.g. Permission.WRITE_EXTERNAL_STORAGE , Permission.READ_EXTERNAL_STORAGE , Permission.CAMERA , Permission.RECORD_AUDIO , etc.
(您不需要安装或导入 android
,只需在 buildozer.spec
的 requirement
android> )
( You don't need to install or import android
, just include android
in the buildozer.spec
's requirement
)
希望对你有帮助(如有不妥请指正)
Hope This Helps (please correct if you find anything is incorrect)
这篇关于Android SDK 工具:OpenCV 需要 Android SDK 工具版本 14 或更新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!