Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Copying APK" fails because of wrong path used #699

Closed
d33tah opened this issue Jul 29, 2018 · 7 comments
Closed

"Copying APK" fails because of wrong path used #699

d33tah opened this issue Jul 29, 2018 · 7 comments

Comments

@d33tah
Copy link

d33tah commented Jul 29, 2018

First of all, here's a Dockerfile describing all steps I took and the environment:

FROM ubuntu:18.04

RUN apt update && apt install python-pip -y

# copied from wiki, just added -y
RUN pip install --upgrade cython==0.21
RUN dpkg --add-architecture i386
RUN apt update
RUN apt install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386 -y

RUN pip install buildozer

RUN useradd user && mkdir -p /home/user && chown -R user /home/user
USER user

WORKDIR /home/user
ADD ./main.py .

RUN buildozer init
RUN buildozer -v android debug || true
ARG CACHE_DATE=not_a_date
RUN buildozer -v android debug

And here's how the build fails:

[DEBUG]:        BUILD SUCCESSFUL
[DEBUG]:        Total time: 3 seconds
[INFO]:    <- directory context /home/user/.buildozer/android/platform/python-for-android-new-toolchain
[INFO]:    # Copying APK to current directory
[INFO]:    # Found APK file: /home/user/.buildozer/android/platform/build/dists/myapp/bin/MyApplication-0.1-debug.apk
stty: 'standard input': Inappropriate ioctl for device
[DEBUG]:   -> running cp /home/user/.buildozer/android/platform/build/dists/myapp/bin/MyApplication-0.1-debug.apk ./
/myapp/private/lib/python2.7/xml/dom/pulldom.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/dom/xmlbuilder.py ...
Listing /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/etree ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/etree/ElementInclude.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/etree/ElementPath.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/etree/ElementTree.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/etree/__init__.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/etree/cElementTree.py ...
Listing /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/parsers ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/parsers/__init__.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/parsers/expat.py ...
Listing /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax/__init__.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax/_exceptions.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax/expatreader.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax/handler.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax/saxutils.py ...
Compiling /home/user/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/xml/sax/xmlreader.py ...
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/user/.buildozer/android/platform/build/dists/myapp/build/outputs/apk/myapp-debug.apk'

The funny part is that the .apk is here, but under a different path:

user@367422efdcb1:~$ find .buildozer -name '*.apk'
.buildozer/android/platform/python-for-android-new-toolchain/MyApplication-0.1-debug.apk
.buildozer/android/platform/build/dists/myapp/bin/MyApplication-0.1-debug-unaligned.apk
.buildozer/android/platform/build/dists/myapp/bin/MyApplication-0.1-debug.apk
.buildozer/android/platform/android-sdk-20/tools/apps/SdkController/bin/SdkControllerApp.apk

Is this a known issue?

@joshuacox
Copy link

joshuacox commented Jul 30, 2018

I can confirm that I see similar in the buildozer official dockerfile does not seem to work either, nor do my modifications in fact it ends very much like yours:
https://gist.github.com/joshuacox/4d4a8ff0cc1eca935980444363f55805

and yet I find similar apks laying around:

find .buildozer -name '*.apk'                                                                                                             ~/git/kivycrashcourse/video2-building_an_android_apk 1 ↵ 
.buildozer/android/platform/python-for-android-new-toolchain/KivyCrashCourse2-1.0-debug.apk
.buildozer/android/platform/build/dists/kivycrash2/bin/KivyCrashCourse2-1.0-debug.apk
.buildozer/android/platform/build/dists/kivycrash2/bin/KivyCrashCourse2-1.0-debug-unaligned.apk

@AndreMiras
Copy link
Member

Yes it is a known bug, see #312, #597, #599, #603, #606, #613, #632, #636, #647, #649, #662, #671 and now #699...
Thank you for reproducing it in Docker. Long story short, it's the gradle detection method that is wrong. Some workaround are given in some of the tickets listed above.

@Archaeus6
Copy link

I also ran into this issue and the Android.py replacement code is not doing the trick. I found the scattered .APK files, but they do not work. I have yet to debug, so I'm just wondering if anyone found a copy in those folders that works as intended?

@DrStoop
Copy link

DrStoop commented Sep 4, 2018

work-around Dockerfile till fix_312 is deployed to pypi

fix_312 was merged already and works for local installation, but docker still fails. the reason is, the Dockerfile builds buildozer from pypi (pip install buildozer) instead from the kivy-repository (pip install -e buildozer/). therefore this issue remains for docker run buildozer ... until the fixed repository is deployed to pypi. meanwhile the following Dockerfile works for me to fix the issue manually:

# Dockerfile for providing buildozer
# Build with:
# docker build --tag=buildozer .
# In order to give the container access to your current working directory
# it must be mounted using the --volume option.
# Run with (e.g. `buildozer --version`):
# docker run --volume "$(pwd)":/home/user/hostcwd buildozer --version
# Or for interactive shell:
# docker run --volume "$(pwd)":/home/user/hostcwd --entrypoint /bin/bash -it --rm buildozer
FROM ubuntu:18.04

ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/hostcwd" \
    PATH="${HOME_DIR}/.local/bin:${PATH}"
ENV FIX_312_FILE="${HOME_DIR}/.local/lib/python2.7/site-packages/buildozer/targets/android.py"
ENV FIX_625_FILE="${HOME_DIR}/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml"

# configures locale
RUN apt update -qq > /dev/null && \
    apt install -qq --yes --no-install-recommends \
    locales && \
    locale-gen en_US.UTF-8
ENV LANG="en_US.UTF-8" \
    LANGUAGE="en_US.UTF-8" \
    LC_ALL="en_US.UTF-8"

# installs system dependencies (required to setup all the tools)
RUN apt install -qq --yes --no-install-recommends \
    sudo python-pip python-setuptools file

# https://buildozer.readthedocs.io/en/latest/installation.html#android-on-ubuntu-18-04-64bit
RUN dpkg --add-architecture i386 && apt update -qq > /dev/null && \
	apt install -qq --yes --no-install-recommends \
	build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 \
	libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 \
	python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386

# prepares non root env
RUN useradd --create-home --shell /bin/bash ${USER}
# with sudo access and no password
RUN usermod -append --groups sudo ${USER}
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER ${USER}
WORKDIR ${WORK_DIR}

# installs buildozer and dependencies
RUN pip install --user Cython==0.25.2 buildozer
# calling buildozer adb command should trigger SDK/NDK first install and update
# but it requires a buildozer.spec file
RUN cd /tmp/ && buildozer init && buildozer android adb -- version && cd -
# fixes source and target JDK version, refs https://github.com/kivy/buildozer/issues/625
RUN sed s/'name="java.source" value="1.5"'/'name="java.source" value="7"'/ -i  ${FIX_625_FILE} \
    && \
    sed s/'name="java.target" value="1.5"'/'name="java.target" value="7"'/ -i ${FIX_625_FILE} \
    && \
# fix 312, refs https://github.com/kivy/buildozer/issues/312 as long as buildozer-fix is not deployed to pypi
    sed --in-place --expression '30ifrom distutils.version import LooseVersion' --in-place ${FIX_312_FILE} \
    && \
    sed --expression '790,793d' --in-place  ${FIX_312_FILE} \
    && \
    sed --expression '790i\        \# fix 312: found how the apd name is really built from the title\n        __sdk_dir = self.android_sdk_dir\n        build_tools_versions = os.listdir(join(__sdk_dir, "build-tools"))\n        build_tools_versions = sorted(build_tools_versions, key=LooseVersion)\n        build_tools_version = build_tools_versions[-1]\n        gradle_files = ["build.gradle", "gradle", "gradlew"]\n        is_gradle_build = any((exists(join(dist_dir, x)) for x in gradle_files)) and build_tools_version >= "25.0"' --in-place ${FIX_312_FILE}

ENTRYPOINT ["buildozer"]

maybe that helps out for a while... have fun!

@BrenBarn
Copy link

BrenBarn commented Oct 1, 2018

When is the fix going to be released? There are multiple tickets for this, going back months, but the error still occurs.

@inclement
Copy link
Member

Closing as stale, I believe this is fixed.

@g1itch
Copy link

g1itch commented May 27, 2020

I have a similar problem with buildozer 0.39. It cannot find the apk because its name is APPNAME__armeabi-v7a-debug-VERSION-.apk

@AndreMiras AndreMiras mentioned this issue Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants