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

IOError: [Errno 2] No such file or directory: 'src/main/assets/private.mp3' #1257

Closed
sjuk opened this issue Apr 10, 2018 · 3 comments
Closed

Comments

@sjuk
Copy link

sjuk commented Apr 10, 2018

I'm on Ubuntu 16.04 (Linux). I'm getting this error at "getting started guide" from https://python-for-android.readthedocs.io/en/latest/quickstart/ with main.py containing hello world example from https://kivy.org/docs/guide/basic.html.
I installed Android Studio with Android SDK and NDK from https://developer.android.com/studio/index.html.
APK-Building was invoked in python virtualenv (because of pip install python-for-android) by following command.
p4a apk --private $HOME/src/kivy --package=org.example.myapp --name "My application" --version 0.1 --bootstrap=sdl2 --requirements=python2,kivy --sdk_dir $HOME/Android/Sdk --ndk_dir ~/Android/Sdk/ndk-bundle --ndk_version r16b

Any idea why building stopped at the following point:
(Thank you in advance...)

Compiling /home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/private/lib/python2.7/xml/sax/xmlreader.py ... Traceback (most recent call last): File "/home/sjuk/env/p4a/bin/p4a", line 11, in <module> sys.exit(main()) File "/home/sjuk/env/p4a/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 975, in main ToolchainCL() File "/home/sjuk/env/p4a/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 512, in __init__ getattr(self, args.subparser_name.replace('-', '_'))(args) File "/home/sjuk/env/p4a/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 150, in wrapper_func func(self, args) File "/home/sjuk/env/p4a/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 754, in apk build_args = build.parse_args(args.unknown_args) File "/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.py", line 567, in parse_args make_package(args) File "/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.py", line 248, in make_package make_tar('src/main/assets/private.mp3', tar_dirs, args.ignore_path) File "/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.py", line 187, in make_tar tf = tarfile.open(tfn, 'w:gz', format=tarfile.USTAR_FORMAT) File "/usr/lib/python2.7/tarfile.py", line 1691, in open return func(name, filemode, fileobj, **kwargs) File "/usr/lib/python2.7/tarfile.py", line 1738, in gzopen fileobj = gzip.GzipFile(name, mode, compresslevel, fileobj) File "/usr/lib/python2.7/gzip.py", line 94, in __init__ fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb') IOError: [Errno 2] No such file or directory: 'src/main/assets/private.mp3'
$ mkdir .local/share/python-for-android/dists/unnamed_dist_1/src/main/assets
and
$ touch .local/share/python-for-android/dists/unnamed_dist_1/src/main/assets/private.mp3

gives me the next complain about another missing file.
Traceback (most recent call last): File "/home/sjuk/env/kivyinstall/bin/p4a", line 11, in <module> sys.exit(main()) File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 975, in main ToolchainCL() File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 512, in __init__ getattr(self, args.subparser_name.replace('-', '_'))(args) File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 150, in wrapper_func func(self, args) File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 754, in apk build_args = build.parse_args(args.unknown_args) File "/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.py", line 567, in parse_args make_package(args) File "/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.py", line 260, in make_package shutil.copy(args.icon or default_icon, 'src/main/res/drawable/icon.png') File "/usr/lib/python2.7/shutil.py", line 119, in copy copyfile(src, dst) File "/usr/lib/python2.7/shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 2] No such file or directory: 'src/main/res/drawable/icon.png'

$ mkdir .local/share/python-for-android/dists/unnamed_dist_1/src/main/res/drawable
$ touch .local/share/python-for-android/dists/unnamed_dist_1/src/main/res/drawable/icon.png
got to the next error...

`INFO: Selecting java build tool:
INFO: Detected highest available build tools version to be 28.0.0-rc1
INFO: Building with ant, as no gradle executable detected
INFO: -> running ant debug
working: Total time: 0 seconds Exception in thread background thread for pid 3720:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/sh.py", line 2170, in background_thread
handle_exit_code(exit_code)
File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/sh.py", line 1929, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/sjuk/env/kivyinstall/local/lib/python2.7/site-packages/sh.py", line 672, in handle_command_exit_code
raise exc
ErrorReturnCode_1:

RAN: /usr/bin/ant debug

STDOUT:
Buildfile: /home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.xml

BUILD FAILED
/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.xml:93: Cannot find /home/sjuk/Android/Sdk/tools/ant/build.xml imported from /home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.xml

Total time: 0 seconds

STDERR:

Buildfile: /home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.xml

BUILD FAILED
/home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.xml:93: Cannot find /home/sjuk/Android/Sdk/tools/ant/build.xml imported from /home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1/build.xml

Total time: 0 seconds
INFO: STDERR:

cd /home/sjuk/.local/share/python-for-android/dists/unnamed_dist_1 && /usr/bin/ant debug

[WARNING]: ERROR: /usr/bin/ant failed!`

@lufebe16
Copy link

lufebe16 commented May 4, 2018

I detected the same problem, when I tried to update an existing (working) build from version 0.5.3 to version 0.6.0. It simply helped to add the missing directories to .... bootstraps/sdl2/build/main/... in the pythonforandroid installation. My init-script now looks like:

...
p4aversion='0.6.0'
ver=`python3 -m pip show python-for-android | grep Version`
echo "Version: $ver"
if [ "$ver" != "Version: $p4aversion" ]
then
  python3 -m  pip install --user "https://github.com/kivy/python-for-android/archive/${p4aversion}.zip"
  # this is a hack! 
  # These 2 directories, present in the downloaded tarball/zip, are lost during installation.
  # I add them again to make shure the build runs through.
  mkdir -p ~/.local/lib64/python3.5/site-packages/pythonforandroid/bootstraps/sdl2/build/src/main/assets
  mkdir -p ~/.local/lib64/python3.5/site-packages/pythonforandroid/bootstraps/sdl2/build/src/main/res/drawable
fi
...

There seems to be a problem somewhere in the setup of pythonforandroid. Also I suggest the build.py script should better check for directories - and fix them if necessary - before creating files.

@lufebe16
Copy link

Here is a patch that applies to the unpacked 0.6.0.zip:

diff -upr python-for-android-0.6.0/pythonforandroid/bootstraps/sdl2/build/build.py python-for-android-0.6.0-p1/pythonforandroid/bootstraps/sdl2/build/build.py
--- python-for-android-0.6.0/pythonforandroid/bootstraps/sdl2/build/build.py	2017-11-25 13:58:38.000000000 +0100
+++ python-for-android-0.6.0-p1/pythonforandroid/bootstraps/sdl2/build/build.py2018-05-04 14:11:35.648338925 +0200
@@ -232,6 +232,7 @@ main.py that loads it.''')
     # Delete the old assets.
     try_unlink('src/main/assets/public.mp3')
     try_unlink('src/main/assets/private.mp3')
+    ensure_dir('src/main/assets')
 
     # In order to speedup import and initial depack,
     # construct a python27.zip
@@ -257,6 +258,7 @@ main.py that loads it.''')
     # Prepare some variables for templating process
     default_icon = 'templates/kivy-icon.png'
     default_presplash = 'templates/kivy-presplash.jpg'
+    ensure_dir('src/main/res/drawable')
     shutil.copy(args.icon or default_icon, 'src/main/res/drawable/icon.png')
     shutil.copy(args.presplash or default_presplash,
                 'src/main/res/drawable/presplash.jpg')

to be saved to 0.6.0.patch, then (e.g):

$ unzip -q "0.6.0.zip"
$ patch -p 0 < "0.6.0.patch"
$ zip -rq "0.6.0.zip" "python-for-android-0.6.0"
$ python3 -m  pip install --user "0.6.0.zip"

@AndreMiras
Copy link
Member

@lufebe16 is this fixed then, should we not close the ticket?

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

4 participants