kivy / kivy/python-for-android
Requirements parsing undefined/ambiguous behavior
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 2k
- Avg merge
- 12h 20m
- Merged PRs (30d)
- 9
Description
### Checklist
- [x] the issue is indeed a bug and not a support request
- [x] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
- [x] I have a short, runnable example that reproduces the issue
- [x] I reproduced the problem with the latest development version (`p4a.branch = develop`)
- [x] I used the grave accent (aka backticks) to format code or logs when appropriated
### Versions
- Python: 3.11.5
- OS: Ubuntu
- Kivy: 2.2.1
- Cython: 0.29.36
- OpenJDK: 17
### Description
I had an issue compiling my kivy application to `.apk`, after a lot of fiddling, I received the solution in the discord channel for the `python-for-android` project. (The content of the application does not matter, as the error happens for the basic application described in kivy's docs).
When running the error on my device I received the error `ImportError: dlopen failed: "/data/data/org.uriyaharpeness.neverfever/files/app/_python_bundle/site-packages/kivy/_clock.so" is for EM_X86_64 (62) instead of EM_AARCH64 (183)`, which was caused apparently because of the way I specified the requirements - using `~=`.
I now know the reason for the failure, which can be seen here:
https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/toolchain.py#L654-L662
The parsing of the requirements supports only no constraints or exact version (`==`) of the packages, and not all the specifications pip supports, which I intuitively used for my requirements.
I have not seen any reference to that issue in the documentation, not a useful comment about this limitation in the `buildozer.spec` file. I would like to suggest a few mitigation steps, for all those theoretical poor souls who could run into the same issue:
1. In the documentation of buildozer - specify that only no constrains or exact version are supported for the requirements.
2. In the initial `buildozer.spec` file - include this limitation in the comment.
3. In the parsing function, called upon compiling - raise an indicative exception if the above requirements are not met.
I would happily try to open a PR for all of these suggestions, but would first like to get some consensus.
> _"The first step in solving a problem is to recognize that it does exist."_
> - Zig Ziglar
### buildozer.spec
Command:
```sh
buildozer android debug
```
Spec file:
```
...
requirements = python3,kivy~=2.2.1
...
```
### Logs
```
...
12-06 16:25:57.472 31566 8670 I python : [ERROR ] [Clock ] Unable to import kivy._clock. Have you perhaps forgotten to compile kivy? Kivy contains Cython code which needs to be compiled. A missing kivy._clock often indicates the Cython code has not been compiled. Please follow the installation instructions and make sure to compile Kivy
12-06 16:25:57.473 31566 8670 I python : Traceback (most recent call last):
12-06 16:25:57.473 31566 8670 I python : File "/home/runner/work/myapp/myapp/.buildozer/android/app/main.py", line 1, in
12-06 16:25:57.475 31566 8670 I python : File "/home/runner/work/myapp/myapp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/neverfever/arm64-v8a/kivy/clock.py", line 466, in
12-06 16:25:57.476 31566 8670 I python : ImportError: dlopen failed: "/data/data/org.uriyaharpeness.neverfever/files/app/_python_bundle/site-packages/kivy/_clock.so" is for EM_X86_64 (62) instead of EM_AARCH64 (183)
12-06 16:25:57.476 31566 8670 I python : Python for android ended.
```
Contributor guide
Research direction
Start with pythonforandroid/toolchain.py lines 654-662 and inspect how requirements such as ~= are parsed. Review the buildozer documentation and initial buildozer.spec references mentioned in the issue, then clarify the supported syntax and expected handling of unsupported constraints. Done means the limitation and behavior are documented or an agreed validation change is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, python
- Domain
- build-system, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100