7

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

1 Answers1

1

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

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 )

Paul Lam
  • 176
  • 2
  • 12
  • There should be no need to both `apt update ` and `apt-get update ` etc; you should simply choose one front and or the other, and stick to that throughout. `apt-get` is more commonly recommended because it transfers easily to automated installations, too, whereas the newer `apt` might have a slightly more pleasant user experience for interactive use; but in the end, they both do the same thing. – tripleee Aug 25 '21 at 17:36
  • @tripleee ok I just edited my post , added in the `apt install` `apt update` part. thanks for the information – Paul Lam Aug 26 '21 at 17:53
  • You seem to have rolled back some rather substantial changes I made; can you explain why? In particular, the erratic spacing around punctuation is quite disturbing, and you should be able to notice several places where line wraps between punctuation and the previous word produce outright jarring layout results as an obvious and unattractive symptom of this. – tripleee Aug 26 '21 at 18:29
  • Also, I can see no actual change around this; you still mix `apt` and `apt-get` with abandon. – tripleee Aug 26 '21 at 18:31
  • @tripleee ok I will combine your edit to my post. And it s me answering this question ( no gonna be rude ) I have my own style…. and I added “either one of the following” on top of the `apt` `apt-get` ; and I know my English is not perfect. I have poor English , I m not native. The formatting of the post may not perfect , I will pay attention to all these. Again , I will edit my post and combine your edits to my post. Is it good enough ? – Paul Lam Aug 27 '21 at 10:33
  • I can reimplement the fixes to the broken orthography if you are not able to, but I'm reluctant to do that again if you are going to roll back things which you want to be broken. The guidelines for this site basically don't allow you to deviate from standards for English orthography but I can try to make the edit less intrusive (leave all the annoying emojis etc). – tripleee Aug 27 '21 at 10:37
  • It's not particularly helpful to leave it up to the user to decide whether to use `apt` or `apt-get`. I would go with the latter for reasons of compatibility with older versions. But just make it consistent, and maybe mention that you could replace it with the other one. – tripleee Aug 27 '21 at 10:39
  • See also https://stackoverflow.com/help/editing and the blog post [In Defense of Editing.](https://stackoverflow.blog/2009/04/08/in-defense-of-editing/) – tripleee Aug 27 '21 at 12:27
  • @tripleee I edited my post , deleted emoji and use `apt-get` for install and upgrade. Hope it can improve this post. And some edits just changed what I mean ( in my point of view , I don't want to argue with you ). but anyway , thanks for improving my post : ) – Paul Lam Aug 27 '21 at 17:09
  • Thanks, I made a lighter edit to just use `apt-get` consistently and fix punctuation errors etc. – tripleee Aug 27 '21 at 19:50