Android SDK 工具:OpenCV 需要 Android SDK 工具修订版 14 或更新版本 [英] Android SDK Tools: OpenCV requires Android SDK Tools revision 14 or newer
问题描述
我正在尝试使用 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
- 构建器 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 并复制粘贴目录部分(最后 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
其中
是所需的 Python 版本.
where <X.X.X>
is the desired Python ver.
安装开发工具 + 依赖项
install dev tools + dependencies
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
)
sudo update-alternatives --config java
sudo update-alternatives --config javac
安装 cmake
(我都做了)(ref )
蟒蛇方式
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/
将其粘贴到 ~/Home/.buildozer/android/platform/android-sdk
之后 压缩位于那里的原始 tools
目录(通过右键单击 --> 压缩 )(如果您看不到目录,请确保选中文件选项中的 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
并在终端中打开
then go to ~/Home/.buildozer/android/platform/android-sdk/tools/bin
and open in terminal
./sdkmanager --install "tools"
exit
重新构建项目转到您的项目目录
rebuild the project again go 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 问题:带有 opencv 的 kivy 相机应用程序android显示黑屏
- Stackoverflow 问题:启动时生成的日志Android 版 Kivy Launcher 中的应用
- Stackoverflow 问题:我无法为 android 构建 buildozer一个>
- Youtube 视频(我关注此视频(复制粘贴目录部分)以使其正常工作): 在 ubuntu 上让 opencv4 与 kivy/buildozer 一起工作
- git 讨论:Android 编译使用 opencv 失败
- Stackoverflow 问题:python 中使用 request_permissions 的 android 权限立>
- python-for-android 文档 - 在 Android 上工作
- 如果您对根目录进行了更改,请关闭终端并重新打开它
- 不要编辑
.bashrc
文件(就我而言,我没有) - 每次重建项目时删除项目目录中的
bin
和.buildozer
目录 OR 运行buildozer
;干净 - 使用
ls
列出当前目录下的所有文件+文件夹 - 使用
cd
导航到目录 - 使用
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 或更新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!