Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SDK Tools: OpenCV requires Android SDK Tools revision 14 or newer

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'

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

But after updated it to 30.0.0 nothing has changed, the error remain same.

I'm using

  1. Ubuntu 19.10
  2. Python 3.7.5
  3. Kivy 1.11.1
  4. Buildozer 1.2.0
  5. openCv 4
like image 698
Mohammad Al-Amin Avatar asked Jun 25 '20 19:06

Mohammad Al-Amin


1 Answers

I get this error too and fretted for a long time : (

After a bunch of google searches , I found some solutions that may help.

At least it works on my Ubuntu 20.04 VM.

( 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 )

  • 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

my 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

Reference

  • Stackoverflow Question: kivy camera application with opencv in android shows black screen
  • Stackoverflow Question: Logs Generated when launching an App in Kivy Launcher on Android
  • Stackoverflow Question: I Can't build buildozer for android
  • Youtube Video (I follow this video (the copy-paste dir part) to make it work): to get opencv4 work with kivy / buildozer on ubuntu
  • git discussion: Android compilation fails with opencv
  • Stackoverflow Question: android permissions in python using request_permissions
  • python-for-android docs - Working on Android

Note

  • 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 )

Hope This Helps ( please correct if you find anything is incorrect )

like image 90
Paul Lam Avatar answered Oct 19 '22 01:10

Paul Lam