Building APK with buildozer on Docker Desktop failed

209 views
Skip to first unread message

Lukas Florner

unread,
Aug 14, 2020, 9:27:58 AM8/14/20
to Kivy users support
Hello,  I try to generate APK with Buildozer running in Docker container (Docker Desktop on Windows 10), but it fails anytime. The image was pulled from https://hub.docker.com/r/kivy/buildozer. When started with docker run --volume ${pwd}:/home/user/hostcwd buildozer init, then buildozer.spec is correctly created, but when I run docker run --volume ${pwd}:/home/user/hostcwd buildozer debug then I encounter error "sh: 0: getcwd() failed: no such file or directory":

...
[INFO]:    Found Android API target in $ANDROIDAPI: 27
[INFO]:    Available Android APIs are (27)
[INFO]:    Requested API target 27 is available, continuing.
...
[INFO]:    kivy has no prebuild_armeabi_v7a, skipping
[INFO]:    # Building recipes
[INFO]:    Building hostpython3 for armeabi-v7a
[INFO]:    -> directory context /home/user/hostcwd/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build
sh: 0: getcwd() failed: No such file or directory
[INFO]:    -> running configure
           working: configure: error: working directory cannot be determined                                                                                                                                      Exception in thread background thread for pid 1214:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 1662, in wrap
    fn(*args, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 2606, in background_thread
    handle_exit_code(exit_code)
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 2304, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 877, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1:

  RAN: /home/user/hostcwd/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/configure

  STDOUT:
sh: 0: getcwd() failed: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
configure: error: working directory cannot be determined

  STDERR:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1260, in <module>
    main()
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 709, in __init__
    getattr(self, command)(args)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 154, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 213, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx,
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 577, in build_recipes
    recipe.build_arch(arch)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/recipes/hostpython3/__init__.py", line 98, in build_arch
    shprint(sh.Command(join(recipe_build_dir, 'configure')))
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
    for line in output:
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 925, in next
    self.wait()
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 849, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/user/.local/lib/python3.8/site-packages/sh.py", line 877, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1:

  RAN: /home/user/hostcwd/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/configure

  STDOUT:
sh: 0: getcwd() failed: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
configure: error: working directory cannot be determined

Till it happens everything seems to be correctly installed (even Android API v.27). When I try to start the container again with debug option, then the error disapears but all the fun ends with another error due to missing Android API:

λ  docker run -i -t -v ${pwd}:/home/user/hostcwd kivy/buildozer -v android debug
# Check configuration tokens
# Ensure build layout
# Create directory /home/user/.buildozer
# Create directory /home/user/.buildozer/cache
# Create directory /home/user/.buildozer/android/platform/android/platform
# Check configuration tokens
# Read available permissions from api-versions.xml
# Preparing build
# Check requirements for android
# Run 'dpkg --version'
# Cwd None
Debian 'dpkg' package management program version 1.19.7 (amd64).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
# Search for Git (git)
#  -> found at /usr/bin/git
# Search for Cython (cython)
#  -> found at /home/user/.local/bin/cython
# Search for Java compiler (javac)
#  -> found at /usr/lib/jvm/java-13-openjdk-amd64/bin/javac
# Search for Java keytool (keytool)
#  -> found at /usr/lib/jvm/java-13-openjdk-amd64/bin/keytool
# Install platform
# Run 'git config --get remote.origin.url'
# Cwd /home/user/hostcwd/.buildozer/android/platform/python-for-android
# Run 'git branch -vv'
# Cwd /home/user/hostcwd/.buildozer/android/platform/python-for-android
* master 1b3b0e3f [origin/master] Merge pull request #2225 from kivy/release-2020.06.02
# Run '/usr/bin/python3 -m pip install -q --user \'appdirs\' \'colorama>=0.3.3\' \'jinja2\' \'six\' \'enum34; python_version<"3.4"\' \'sh>=1.10; sys_platform!="nt"\' \'pep517<0.7.0"\' \'toml\''
# Cwd None
# Android ANT is missing, downloading
# Run 'tar xzf apache-ant-1.9.4-bin.tar.gz'
# Cwd /home/user/.buildozer/android/platform/apache-ant-1.9.4
# Apache ANT installation done.
# Android SDK is missing, downloading
# Unpacking Android SDK
# Run 'unzip -q /home/user/.buildozer/android/platform/android-sdk/commandlinetools-linux-6514223_latest.zip'
# Cwd /home/user/.buildozer/android/platform/android-sdk
# Android SDK tools base installation done.
# Recommended android's NDK version by p4a is: 19c
# Android NDK is missing, downloading
# Unpacking Android NDK
# Run 'unzip -q /home/user/.buildozer/android/platform/android-ndk-r19c-linux-x86_64.zip'
# Cwd /home/user/.buildozer/android/platform
# Rename /home/user/.buildozer/android/platform/android-ndk-r19c to /home/user/.buildozer/android/platform/android-ndk-r19c
# Android NDK installation done.
# Read available permissions from api-versions.xml
# Check application requirements
# Compile platform
# Run '/usr/bin/python3 -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=python3,kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/home/user/hostcwd/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21'
# Cwd /home/user/hostcwd/.buildozer/android/platform/python-for-android
/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py:84: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
[INFO]:    Will compile for the following archs: armeabi-v7a
[INFO]:    Found Android API target in $ANDROIDAPI: 27
[INFO]:    Available Android APIs are ()
[ERROR]:   Build failed: Requested API target 27 is not available, install it with the SDK android tool. 

I suppose that the main issue is in the first error but cannot find a way how to solve it.

Robert Flatt

unread,
Aug 14, 2020, 1:19:16 PM8/14/20
to Kivy users support
This doesn't look like a Kivy issue, is this a docker usage issue ?
I use WSL so I have never tried this.
 
What shell are you using that expands ${pwd}   to the working drectory?  I would have expected %cd%  on Windows.

Try a literal path.

Builddozer init probably works because it doesn't care where it is, it just writes a file in './'

Lukas Florner

unread,
Aug 14, 2020, 2:35:43 PM8/14/20
to Kivy users support
I've tried PowerShell and Cmder. The result is the same with ${pwd}: or D:/FIM/MOAP/Kivy_01/apks:

Lukas Florner

unread,
Aug 14, 2020, 2:45:28 PM8/14/20
to Kivy users support
Strange thing is that docker run -i -t -v ${pwd}:/home/user/hostcwd kivy/buildozer -v android debug creates whole folder structure and downloads and unzip many files into the working directory. The process fails somewhere in the middle. 

Robert Flatt

unread,
Aug 14, 2020, 3:51:55 PM8/14/20
to Kivy users support
No idea what -i -t does, but if it gets past the getcwd() issues, great.

The process fails somewhere in the middle

As it says at the end of the Buildozer log, set 'log_level = 2'  and rerun.
If you don't understand the error, post the full new log here as a .txt and somebody will probably be able to help.

Lukas Florner

unread,
Aug 15, 2020, 3:31:56 AM8/15/20
to Kivy users support
Log enclosed. I've tried to change location and removed -i -t (are not necessary in this case) but still no result...
docker_log.txt

Robert Flatt

unread,
Aug 15, 2020, 1:00:55 PM8/15/20
to Kivy users support
Sorry, I've never seen anything like this.
The issue is, I expect, either with the docker image or the way it is used.

Anybody else have a suggestion?

Any alternative is WSL or VirtualBox.
Reply all
Reply to author
Forward
0 new messages