Android SDK 工具:OpenCV 需要 Android SDK 工具版本 14 或更高。

7
我试图使用 Kivy 和 OpenCV 创建一个简单的照片捕捉应用程序。当我尝试使用 buildozer 创建 .apk 文件并在 .spec 文件中将 OpenCV 加入要求时,我遇到了以下错误。
-- 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)这个文件夹并使用以下命令进行了更新:

sudo apt-get upgrade

但是在更新到30.0.0版本后,没有任何变化,错误仍然存在。

我使用的环境包括:

  1. Ubuntu 19.10
  2. Python 3.7.5
  3. Kivy 1.11.1
  4. Buildozer 1.2.0
  5. OpenCV 4
1个回答

1
我也遇到了这个错误,苦恼了很长时间 :(
经过一系列的谷歌搜索,我找到了一些可能有用的解决方案。
至少在我的Ubuntu 20.04虚拟机上可以使用。
(按照下载Android Studio和复制粘贴dir部分的说明(最后3步)可能会解决您的问题,因为我也遇到了与您相同的错误)
  • first update apt

    sudo apt-get update
    
  • upgrade pkgs

    sudo apt-get upgrade
    
  • install python3 + pip

    sudo apt-get install python3 python3-pip
    
  • config default Python version ( ref_1 ) ( ref_2 )

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python<X.X.X> 1
    sudo update-alternatives --config 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
    
  • install kivy

    • through apt

      sudo apt-get install python3-kivy
      
    • through Python pip ( my preferred way )

      python3 -m pip install kivy==2.0.0
      
  • install cython

    pip3 install Cython
    sudo apt-get install cython
    

    // I do it in this way

  • install javac

    sudo apt-get install openjdk-11-jdk openjdk-8-jdk
    
  • check if java and javac are installed

    java -version
    javac -version
    
  • config. java + javac ( I config. it to openjdk8-jdk )

    sudo update-alternatives --config java
    
    sudo update-alternatives --config javac
    
  • install cmake ( I did both of it ) ( 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
      
  • install buildozer ( I reinstalled it using the official way )

    • official way

      pip3 install --user --upgrade buildozer
      
    • through git clone

      sudo apt-get install git
      git clone https://github.com/kivy/buildozer.git
      cd buildozer
      sudo python3 setup.py install
      
  • install Python IDLE ( optional ) ( either one of the following )

    sudo apt-get install idle3
    
  • install Android Studio

    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.

    After that, just close it

  • after everything is set up : ( ref )

    open file

    copy the tools dir located in ~/Home/Android/Sdk/

    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 )

    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 will be available in 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

参考资料

注意
  • 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 run buildozer <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 the buildozer.spec's permission 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.
    
    ( You don't need to install or import android , just include android in the buildozer.spec's requirement )
希望这能帮到您(如果您发现任何错误,请纠正)。

@tripleee 好的,我刚刚编辑了我的帖子,在apt installapt update部分添加了内容。感谢您提供的信息。 - Paul Lam
你似乎撤销了我所做的一些相当重要的更改;你能解释一下为什么吗?特别是,标点周围的不规则间距非常令人不安,你应该能够注意到有几个地方,在标点和前一个单词之间换行会产生明显的刺耳布局结果,这是一个明显而不美观的症状。 - tripleee
如果您无法修复拼写错误,我可以重新实现修复,但是如果您要撤回那些您希望出现问题的内容,我不愿再次这样做。该网站的准则基本上不允许您偏离英语正字法标准,但我可以尝试使编辑变得不那么显眼(保留所有令人烦恼的表情符等)。 - tripleee
让用户决定是使用apt还是apt-get并不特别有帮助。出于与旧版本的兼容性原因,我会选择后者。但是请保持一致,并可能提到您可以将其替换为另一个。 - tripleee
@tripleee 我编辑了我的帖子,删除了表情符号并使用 apt-get 进行安装和升级。希望这可以改善这篇文章。有些编辑只是改变了我的意思(在我看来,我不想与你争论)。但无论如何,感谢您改进我的帖子:) - Paul Lam
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接