EDIT: https://github.com/kivy/kivy/issues/4095 seems to be the same issue, but nobody has gotten an answer from there.
Hi, when I run an apk which has the pillow imported in it (from PIL import Image) it will crash on startup citing this, and force closing:
ImportError: dlopen failed: "/data/data/org.benjimaestro.hypertext/files/app/lib/python2.7/site-packages/PIL/_imaging.so" is 64-bit instead of 32-bit
My buildozer.spec is this:
```[app]
title = HyperText
package.name = hypertext
package.domain = org.benjimaestro
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
requirements = kivy,hostpython2,plyer,android,pil,pillow
#
#
#
osx.python_version = 3
osx.kivy_version = 1.9.1
#
#
fullscreen = 0
android.permissions = INTERNET,VIBRATE,BIND_NOTIFICATION_LISTENER_SERVICE,STATUS_BAR
android.api = 21
android.minapi = 9
android.sdk = 20
android.ndk = 9c
android.add_libs_armeabi = libs/android/.so
android.add_libs_armeabi_v7a = libs/android-v7/.so
android.arch = armeabi-v7a
p4a.source_dir = /home/benjamin/python-for-android
I am using Python 3.5 64bit on Ubuntu 64bit. The Pillow module was installed with pip.
Thanks for the report, it sounds like the PIL recipe has a bug.
Well it could have a bug indeed, but your buildozer.spec seems wrong to me. Since you've added both pil and pillow in here:
requirements = kivy,hostpython2,plyer,android,pil,pillow
But pillow does not (yet) have a recipe, see #786.
So the error you're having would definitely happen if you try to build/install an extension which has no recipe. Even if the pil recipe was not broken ;)
I could successfully test the PIL module on my install. Since you installed pillow once, you need to make sure it's completely cleared before trying again with PIL. I remember I had some issues with that where the previous pillow install was remaining. You could try to manually delete the Android application as well as running:
buildozer android p4a -- clean_recipe_build pil
Before doing your build and deployment again, good luck :)
Thanks @AndreMiras, I'll close this. If there are specific issues with the pil recipe, feel free to open a new issue about them.
For what it's worth, I intend to look at fixing up the recipes after the next release.
I've been trying to fix this error for a pretty long time. I did what you said and now my app is running on Android. Thank you @AndreMiras You are my personal jesus christ :)
11-29 14:35:39.919 28341 28361 I python : Traceback (most recent call last):
11-29 14:35:39.920 28341 28361 I python : File "/home/kivydev/test/py2apk/main.py", line 6, in
11-29 14:35:39.920 28341 28361 I python : File "/home/kivydev/test/py2apk/autologin.py", line 27, in
11-29 14:35:39.920 28341 28361 I python : File "/home/kivydev/.local/share/python-for-android/dists/py2dist/private/lib/python2.7/site-packages/PIL/Image.py", line 64, in
11-29 14:35:39.920 28341 28361 I python : ImportError: dlopen failed: "/data/data/com.myapp.test/files/app/lib/python2.7/site-packages/PIL/_imaging.so" is 64-bit instead of 32-bit
11-29 14:35:39.944 28341 28361 I python : Python for android ended.
How to solve the question?I I haven't found a way to find it for a long time.
@Subdue0 you need to add the exact variant that has a p4a recipe to your --requirements as in the p4a option, or if you use buildozer, the buildozer.spec requirements entry. Adding it to your project's requirements.txt or similar is not sufficient. For a python 2 app, both pil and Pillow should work, for Python 3 use Pillow. Also, I'm not sure the recipes are in working order in p4a's stable, so you may need to use the git master development version. (someone else can possibly correct me on this) You can install the p4a dev version using pip install -U https://github.com/kivy/python-for-android/archive/master.zip
And try what @AndreMiras suggested above, which is:
unnamed_dist_1 or similar in the p4a build subfolder, you should be able to find it on Linux using sudo updatedb && locate unnamed_dist) such that it is recreated from scratch next timebuildozer android p4a -- clean_recipe_build pilHope that helps. You can also drop by on the discord where we might be able to help you better
@JonasT I have tried all of the above, but none of them can be solved. My p4a 's 'recipes' contains Pillow and pil, no pillow, and if i use 'pillow' in the requirements, it can be successfully packaged, but the APK cannot be run ('_imaging.so" is 64-bit instead of 32 -bit'), the other will have errors when packaging.
if i use 'pillow' in the requirements
On recent stable this might give you no recipe. That will obviously build but not anything useful (as evidenced by the error at runtime).
the other will have errors when packaging
If you don't give us the detailed errors, nobody can help you :cry:
working: /home/kivydev/andr/android-ndk-r16b/bu...(and 73 more) Exception in thread background thread for pid 9708:
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/kivydev/.local/lib/python2.7/site-packages/sh.py", line 1540, in wrap
fn(args, *kwargs)
File "/home/kivydev/.local/lib/python2.7/site-packages/sh.py", line 2459, in background_thread
handle_exit_code(exit_code)
File "/home/kivydev/.local/lib/python2.7/site-packages/sh.py", line 2157, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/kivydev/.local/lib/python2.7/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
ErrorReturnCode_2:
RAN: /home/kivydev/andr/android-ndk-r16b/ndk-build V=1 APP_ABI=armeabi-v7a
STDOUT:
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
Android NDK: APP_PLATFORM set to unknown platform: android-14.
/home/kivydev/andr/android-ndk-r16b/build/core/setup-app-platform.mk:135: * Android NDK: Aborting . Stop.
STDERR:
Traceback (most recent call last):
File "/home/kivydev/.local/bin/p4a", line 11, in
sys.exit(main())
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 973, in main
ToolchainCL()
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 512, in __init__
getattr(self, args.subparser_name.replace('-', '_'))(args)
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 147, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 191, in build_dist_from_args
build_recipes(build_order, python_modules, ctx)
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/build.py", line 573, in build_recipes
recipe.build_arch(arch)
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/recipes/jpeg/__init__.py", line 29, in build_arch
super(JpegRecipe, self).build_arch(arch)
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/recipe.py", line 685, in build_arch
shprint(sh.ndk_build, 'V=1', 'APP_ABI=' + arch.arch, *extra_args, _env=env)
File "/home/kivydev/.local/lib/python2.7/site-packages/pythonforandroid/logger.py", line 176, in shprint
for line in output:
File "/home/kivydev/.local/lib/python2.7/site-packages/sh.py", line 863, in next
self.wait()
File "/home/kivydev/.local/lib/python2.7/site-packages/sh.py", line 792, in wait
self.handle_command_exit_code(exit_code)
File "/home/kivydev/.local/lib/python2.7/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_2:
RAN: /home/kivydev/andr/android-ndk-r16b/ndk-build V=1 APP_ABI=armeabi-v7a
STDOUT:
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
Android NDK: APP_PLATFORM set to unknown platform: android-14.
/home/kivydev/andr/android-ndk-r16b/build/core/setup-app-platform.mk:135: * Android NDK: Aborting . Stop.
STDERR:
--dist_name py2dist
--android_api 19
--minsdk 19
--sdk_dir /home/kivydev/andr/android-sdk-linux
--ndk_dir /home/kivydev/andr/android-ndk-r16b
--ndk_version 16
--arch armeabi-v7a
--requirements python2,kivy,requests,Pillow
--private .
--package com.myapp.test
--name pytest
--version 1.0
--bootstrap sdl2
It appears as if p4a doesn't pass the correct the NDK version along to the NDK makefile to me. I don't think this is related to pil/Pillow in any way, it looks like a generic p4a bug. Can you file a new ticket with this backtrace so we can see what needs fixing?
(My spontaneous guess is that the ndk-build call quoted in RAN would need to add the APP_PLATFORM option, but I'm sure other devs also have some ideas)
Also what p4a version is this? Could you possibly try git master if this is the pypi or some other stable/older version to see if that changes anything?
Just to clarify: with new ticket I mean create one here: https://github.com/kivy/python-for-android/issues/new you could title it ndk-build error during build or something
Most helpful comment
Thanks @AndreMiras, I'll close this. If there are specific issues with the pil recipe, feel free to open a new issue about them.
For what it's worth, I intend to look at fixing up the recipes after the next release.