buildozer(kivy,python) 无法将生成的 apk 复制到 docker 虚拟机上的主目录

Posted

技术标签:

【中文标题】buildozer(kivy,python) 无法将生成的 apk 复制到 docker 虚拟机上的主目录【英文标题】:buildozer(kivy,python) failed in copying generated apk to the home dir on docker virtual machine 【发布时间】:2018-07-03 00:42:32 【问题描述】:

我尝试在docker虚拟机中运行buildozer来生成andorid app package(.apk)。

经过多次尝试和归档,他的 Dockerfile(https://github.com/jedie/kivy-buildozer-docker) 决定用于为我的目的创建我的环境。

但是,在几乎完成的构建中,发生了错误。

.apk 已成功生成,但(我猜)错误是导致 .apk 文件从生成的工作目录复制到 project_dir 的过程,如下所示。

[INFO]:    <- directory context /home/buildozer/kivy_hello_world/.buildozer/android/platform/python-for-android-new-toolchain
[INFO]:    # Copying APK to current directory
[INFO]:    # Found APK file: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/HelloWorld-0.1-debug.apk
[DEBUG]:   -> running cp /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/HelloWorld-0.1-debug.apk ./
Traceback (most recent call last):
  File "/usr/local/bin/buildozer", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/buildozer/scripts/client.py", line 13, in main
    Buildozer().run_command(sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/buildozer/__init__.py", line 1058, in run_command
    self.target.run_commands(args)
  File "/usr/local/lib/python2.7/dist-packages/buildozer/target.py", line 92, in run_commands
    func(args)
  File "/usr/local/lib/python2.7/dist-packages/buildozer/target.py", line 104, in cmd_debug
    self.buildozer.build()
  File "/usr/local/lib/python2.7/dist-packages/buildozer/__init__.py", line 212, in build
    self.target.build_package()
  File "/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py", line 817, in build_package
    copyfile(join(apk_dir, apk), join(self.buildozer.bin_dir, apk_dest))
  File "/usr/lib/python2.7/shutil.py", line 96, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: u'/home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/build/outputs/apk/kivy_hello_world-debug.apk'

IOError的最后一句中,存在之前的路径/home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/

IOError: [Errno 2] No such file or directory: u'/home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/build/outputs/apk/kivy_hello_world-debug.apk'

但是,后一个路径 `build/outputs/apk/kivy_hello_world-debug.apk' 不存在。

有什么办法解决这个问题? (这发生在从 buildozer 调用的 python-for-android 中) (未解决:apt-get install binfmt-support)

规格。 机器:MacBookPro、mac serria(10.12.6) Docker:Docker 版本 18.01.0-ce,构建 03596f5 Docker:docker-machine 版本 0.13.0,构建 9ba6da9 Buildozer:v.034 python-for-android:获取版本。由 buildozer 提供。

尝试了一点定制的 Dockerfile。

FROM ubuntu:17.10

MAINTAINER Jens Diemer "https://github.com/jedie/kivy-buildozer-docker"

# Update ubuntu:
RUN set -x \
    && apt-get update -qq \
    && apt-get -y full-upgrade \
    && apt-get autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# install needed packages for buildozer
# base is https://github.com/kivy/buildozer/blob/master/buildozer/tools/packer/scripts/additional-packages.sh
# But we need some more tools here ;)
RUN set -x \
    && dpkg --add-architecture i386 \
    && apt-get update -qq \
    && apt-get -y install \
        lib32stdc++6 lib32z1 lib32ncurses5 \
        build-essential \
        python-pip unzip curl \
    && apt-get -y install git openjdk-8-jdk --no-install-recommends zlib1g-dev \
    && apt-get autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# The buildozer VM used Cython v0.25 and buildozer v0.32
RUN set -x \
    && pip install -U pip \
    && pip install "cython<0.26" \
    && pip install "buildozer!=0.33" python-for-android pyOpenssl

ADD kivy_hello_world /home/buildozer/kivy_hello_world

RUN set -x \
    && adduser buildozer --disabled-password --disabled-login \
    && chown -R buildozer:buildozer /home/buildozer/

USER buildozer

# download all needed andorid dependencies:
RUN set -x \
    && cd /home/buildozer/kivy_hello_world \
    && buildozer -v android debug \
    && cd .. \
    && rm -rf kivy_hello_world

VOLUME /home/buildozer/

WORKDIR /home/buildozer/

已建立的长日志。最后几行显示错误消息

Compiling /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/private/lib/python2.7/xml/sax/saxutils.py ...
Compiling /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/private/lib/python2.7/xml/sax/xmlreader.py ...
[INFO]:    Selecting java build tool:
[INFO]:    Detected highest available build tools version to be 19.1.0
[INFO]:        Building with ant, as the highest build-tools-version is only 19.1.0
[DEBUG]:   -> running ant debug
[DEBUG]:    Buildfile: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/build.xml
[DEBUG]:    
[DEBUG]:    -set-mode-check:
[DEBUG]:    
[DEBUG]:    -set-debug-files:
[DEBUG]:    
[DEBUG]:    -check-env:
[DEBUG]:     [checkenv] Android SDK Tools Revision 22.6.2
[DEBUG]:     [checkenv] Installed at /home/buildozer/.buildozer/android/platform/android-sdk-21
[DEBUG]:    
[DEBUG]:    -setup:
[DEBUG]:         [echo] Project Name: HelloWorld-0.1
[DEBUG]:      [gettype] Project Type: Application
[DEBUG]:    
[DEBUG]:    -set-debug-mode:
[DEBUG]:    
[DEBUG]:    -debug-obfuscation-check:
[DEBUG]:    
[DEBUG]:    -pre-build:
[DEBUG]:         [copy] Copying 25 files to /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/tmp-src
[DEBUG]:    
[DEBUG]:    -build-setup:
[DEBUG]:    [getbuildtools] Using latest Build Tools: 19.1.0
[DEBUG]:         [echo] Resolving Build Target for HelloWorld-0.1...
[DEBUG]:    [gettarget] Project Target:   Android 4.4.2
[DEBUG]:    [gettarget] API level:        19
[DEBUG]:         [echo] ----------
[DEBUG]:         [echo] Creating output directories if needed...
[DEBUG]:        [mkdir] Created dir: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/rsObj
[DEBUG]:        [mkdir] Created dir: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/rsLibs
[DEBUG]:         [echo] ----------
[DEBUG]:         [echo] Resolving Dependencies for HelloWorld-0.1...
[DEBUG]:    [dependency] Library dependencies:
[DEBUG]:    [dependency] No Libraries
[DEBUG]:    [dependency]
[DEBUG]:    [dependency] ------------------
[DEBUG]:         [echo] ----------
[DEBUG]:         [echo] Building Libraries with 'debug'...
[DEBUG]:       [subant] No sub-builds to iterate on
[DEBUG]:    
[DEBUG]:    -code-gen:
[DEBUG]:    [mergemanifest] Found modified input file
[DEBUG]:    [mergemanifest] Merging AndroidManifest files into one.
[DEBUG]:    [mergemanifest] Manifest merger disabled. Using project manifest only.
[DEBUG]:         [echo] Handling aidl files...
[DEBUG]:         [aidl] No AIDL files to compile.
[DEBUG]:         [echo] ----------
[DEBUG]:         [echo] Handling RenderScript files...
[DEBUG]:         [echo] ----------
[DEBUG]:         [echo] Handling Resources...
[DEBUG]:         [aapt] Found new input file
[DEBUG]:         [aapt] Generating resource IDs...
[DEBUG]:         [aapt]     (skipping file '.gitkeep' due to ANDROID_AAPT_IGNORE pattern '.*')
[DEBUG]:         [echo] ----------
[DEBUG]:         [echo] Handling BuildConfig class...
[DEBUG]:    [buildconfig] No need to generate new BuildConfig.
[DEBUG]:    
[DEBUG]:    -pre-compile:
[DEBUG]:    
[DEBUG]:    -compile:
[DEBUG]:        [javac] Compiling 25 source files to /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/classes
[DEBUG]:        [javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
[DEBUG]:        [javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
[DEBUG]:        [javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
[DEBUG]:        [javac] Note: Some input files use or override a deprecated API.
[DEBUG]:        [javac] Note: Recompile with -Xlint:deprecation for details.
[DEBUG]:        [javac] 3 warnings
[DEBUG]:    
[DEBUG]:    -post-compile:
[DEBUG]:    
[DEBUG]:    -obfuscate:
[DEBUG]:    
[DEBUG]:    -dex:
[DEBUG]:          [dex] input: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/classes
[DEBUG]:          [dex] Found modified input file
[DEBUG]:          [dex] Converting compiled files and external libraries into /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/classes.dex...
[DEBUG]:    
[DEBUG]:    -crunch:
[DEBUG]:       [crunch] Crunching PNG Files in source dir: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/src/main/res
[DEBUG]:       [crunch] To destination dir: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/res
[DEBUG]:       [crunch] Processing image to cache: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/src/main/res/drawable/icon.png => /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/res/drawable/icon.png
[DEBUG]:       [crunch]   (processed image to cache entry /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/res/drawable/icon.png: 126% size of source)
[DEBUG]:       [crunch] Crunched 1 PNG files to update cache
[DEBUG]:    
[DEBUG]:    -package-resources:
[DEBUG]:         [aapt] Found modified input file
[DEBUG]:         [aapt] Creating full resource package...
[DEBUG]:         [aapt]     (skipping file '.gitkeep' due to ANDROID_AAPT_IGNORE pattern '.*')
[DEBUG]:         [aapt]     (skipping file '.gitkeep' due to ANDROID_AAPT_IGNORE pattern '.*')
[DEBUG]:    
[DEBUG]:    -package:
[DEBUG]:    [apkbuilder] Found modified input file
[DEBUG]:    [apkbuilder] Creating HelloWorld-0.1-debug-unaligned.apk and signing it with a debug key...
[DEBUG]:    
[DEBUG]:    -post-package:
[DEBUG]:    
[DEBUG]:    -do-debug:
[DEBUG]:     [zipalign] Running zip align on final apk...
[DEBUG]:         [echo] Debug Package: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/HelloWorld-0.1-debug.apk
[DEBUG]:    [propertyfile] Updating property file: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/build.prop
[DEBUG]:    [propertyfile] Updating property file: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/build.prop
[DEBUG]:    [propertyfile] Updating property file: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/build.prop
[DEBUG]:    [propertyfile] Updating property file: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/build.prop
[DEBUG]:    
[DEBUG]:    -post-build:
[DEBUG]:       [delete] Deleting directory /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/tmp-src
[DEBUG]:    
[DEBUG]:    debug:
[DEBUG]:    
[DEBUG]:    BUILD SUCCESSFUL
[DEBUG]:    Total time: 12 seconds
[INFO]:    <- directory context /home/buildozer/kivy_hello_world/.buildozer/android/platform/python-for-android-new-toolchain
[INFO]:    # Copying APK to current directory
[INFO]:    # Found APK file: /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/HelloWorld-0.1-debug.apk
[DEBUG]:   -> running cp /home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin/HelloWorld-0.1-debug.apk ./
Traceback (most recent call last):
  File "/usr/local/bin/buildozer", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/buildozer/scripts/client.py", line 13, in main
    Buildozer().run_command(sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/buildozer/__init__.py", line 1058, in run_command
    self.target.run_commands(args)
  File "/usr/local/lib/python2.7/dist-packages/buildozer/target.py", line 92, in run_commands
    func(args)
  File "/usr/local/lib/python2.7/dist-packages/buildozer/target.py", line 104, in cmd_debug
    self.buildozer.build()
  File "/usr/local/lib/python2.7/dist-packages/buildozer/__init__.py", line 212, in build
    self.target.build_package()
  File "/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py", line 817, in build_package
    copyfile(join(apk_dir, apk), join(self.buildozer.bin_dir, apk_dest))
  File "/usr/lib/python2.7/shutil.py", line 96, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: u'/home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/build/outputs/apk/kivy_hello_world-debug.apk'

【问题讨论】:

【参考方案1】:

这是buildozer复制apk的BUG,你可以在/home/buildozer/kivy_hello_world/.buildozer/android/platform/build/dists/kivy_hello_world/bin找到apk。

【讨论】:

谢谢,不客气。是的,我同意你的看法。我使用这个构建环境。对于初学者学习,因此很难手动复制修复。我的想法要解决; (1)放弃,(2)修复了docker上的vm for buildozer可以正确复制.apk文件(3)我尝试修复buildozer的这个bug。我认为最好的是(2)。

以上是关于buildozer(kivy,python) 无法将生成的 apk 复制到 docker 虚拟机上的主目录的主要内容,如果未能解决你的问题,请参考以下文章

Python、Kivy、Buildozer:使用 python-firebase/requests 时出错

无法使用 buildozer 编译 python 脚本

《Buildozer打包实战指南》第二节 安装Kivy和Buildozer

《Buildozer打包实战指南》第二节 安装Kivy和Buildozer

Python/Kivy/Buildozer - 应用程序在 Android 中崩溃,但在 PC 上运行良好

Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m "kivy" d