Problem in conversion from python (kivy,kivymd) to APK using buildozer - kivy

I tried several times to convert my kivy/kivymd app into a working apk but I failed miserably at every attempt.
This is the code from google colab.
!pip install cython==0.29.19
!sudo apt-get install -y \
python3-pip \
build-essential \
git \
python3 \
python3-dev \
ffmpeg \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-ttf-dev \
libportmidi-dev \
libswscale-dev \
libavformat-dev \
libavcodec-dev \
zlib1g-dev
!sudo apt-get install -y \
libgstreamer1.0 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good
!sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev libffi6
!sudo apt-get install libffi-dev
this is my compiled requirements in buildozer spec ...
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,Kivy==1.11.1,sdl2_ttf==2.0.15,kivymd==0.104.2,ccxt==1.84.75,pybit,pandas,stockstats,requests,urllib3,chardet,idna,websocket,websocket-client,cryptography, beautifulsoup4
I also tried kivy==2.0.0
always in spec file . . .
# (list) The Android archs to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
# In past, was `android.arch` as we weren't supporting builds for multiple archs at the
same time.
android.archs= arm64-v8a, x86_64
I tried also. . .
# (list) The Android archs to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
# In past, was `android.arch` as we weren't supporting builds for multiple archs at the
same time.
android.archs = arm64-v8a, armeabi-v7a
The app is succesfully converted every time but it crashes after the splashscreen.
This is the result of adb logcat
10-08 21:46:17.781 3057 3077 I python : Android kivy bootstrap done. __name__ is
__main__
10-08 21:46:17.781 3057 3077 I python : AND: Ran string
10-08 21:46:17.781 3057 3077 I python : Run user program, change dir and execute
entrypoint
10-08 21:46:17.830 1316 1337 I ActivityManager: Displayed
org.kappazeta.heartbot/org.kivy.android.PythonActivity: +475ms
10-08 21:46:17.845 3057 3077 I python : /content/.buildozer/android/platform/build-
arm64-v8a_x86_64/build/python-installs/heartbot/x86_64/bs4/element.py:15: UserWarning:
The soupsieve package is not installed. CSS selectors cannot be used.
10-08 21:46:17.862 3057 3057 V SDL : surfaceChanged()
10-08 21:46:17.862 3057 3057 V SDL : pixel format RGB_565
10-08 21:46:17.862 3057 3057 V SDL : Window size: 1080x2341
10-08 21:46:17.862 3057 3057 V SDL : Device size: 1080x2400
10-08 21:46:17.954 3057 3077 I python : [INFO ] [Logger ] Record log in
/data/user/0/org.kappazeta.heartbot/files/app/.kivy/logs/kivy_22-10-08_5.txt
10-08 21:46:17.955 3057 3077 I python : [INFO ] [Kivy ] v2.0.0
10-08 21:46:17.955 3057 3077 I python : [INFO ] [Kivy ] Installed at
"/data/user/0/org.kappazeta.heartbot/files/app/_python_bundle/site-
packages/kivy/__init__.pyc"
10-08 21:46:17.955 3057 3077 I python : [INFO ] [Python ] v3.9.9 (main, Oct 8
2022, 18:44:24)
10-08 21:46:17.955 3057 3077 I python : [Clang 12.0.8
(https://android.googlesource.com/toolchain/llvm-project c935d99d
10-08 21:46:17.955 3057 3077 I python : [INFO ] [Python ] Interpreter at ""
10-08 21:46:17.956 3057 3077 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
10-08 21:46:17.956 3057 3077 I python : Traceback (most recent call last):
10-08 21:46:17.956 3057 3077 I python : File
"/content/.buildozer/android/app/main.py", line 6, in <module>
10-08 21:46:17.956 3057 3077 I python : File
"/content/.buildozer/android/platform/build-arm64-v8a_x86_64/build/python-
installs/heartbot/x86_64/kivy/storage/__init__.py", line 124, in <module>
10-08 21:46:17.956 3057 3077 I python : File
"/content/.buildozer/android/platform/build-arm64-v8a_x86_64/build/python-
installs/heartbot/x86_64/kivy/clock.py", line 466, in <module>
10-08 21:46:17.957 3057 3077 I python : ModuleNotFoundError: No module named
'kivy._clock'
10-08 21:46:17.957 3057 3077 I python : Python for android ended.
I tried to understand especially this advice "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." .
I previously converted apps from kivy to apk with google colabs without any problem but now I realized that I really need a clarification. How can I finally convert my app? What is my error/errors?
Thanks for your attention

Related

ERR: "Biopython requires Python 3.6 or later. Python 2.7 detected". Even though I'm running python version 3.10.6

I'm trying to build a docker image from the docker file:
FROM ubuntu:18.04
# Install tzdata
RUN apt-get update &&\
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
# Install Python, Bowtie2 and Java
RUN apt-get install -y python3.10 python3-pip \
openjdk-8-jdk \
bowtie2 \
wget
RUN apt-get install --yes --no-install-recommends \
zlib1g-dev \
libbz2-dev \
liblzma-dev
# Install RSeQC
RUN apt-get install -y python-pip &&\
pip install RSeQC
# Install biopython=1.80
RUN pip install biopython
# Install Atria
RUN wget https://github.com/cihga39871/Atria/releases/download/v3.1.2/atria-3.1.2-linux.tar.gz && \
tar -zxf atria-3.1.2-linux.tar.gz && \
mv atria-3.1.2/bin/atria /usr/local/bin/atria && \
chmod +x /usr/local/bin/atria
#Atria dependencies
RUN apt-get install pigz pbzip2
# Install findtail
RUN wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/findtail/findtail_v1.01 && \
mv findtail_v1.01 /usr/local/bin/findtail_v1.01 && \
chmod +x /usr/local/bin/findtail_v1.01
# Cleanup
RUN apt clean
But while on Step 6/10 : RUN pip install biopython it gives the error :
---> Running in 062f9c27cc15
Collecting biopython
Downloading https://files.pythonhosted.org/packages/3d/2f/d9df24de05d651c5e686ee8fea3afe3985c03ef9ca02f4cc1e7ea10aa31e/biopython-1.77.tar.gz (16.8MB)
Complete output from command python setup.py egg_info:
Biopython requires Python 3.6 or later. Python 2.7 detected.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-mgUybW/biopython/
The command '/bin/sh -c pip install biopython' returned a non-zero code: 1
I've check the python version on my pc. I'm running python version 3.10.6 on my OS and in the dockerfile I'm trying to incorporate python 3.10 version. Where is this error coming from?
The default Python version in Ubuntu 18.04 is 3.6. However, on line 19, you are installing the python-pip package, i.e. the Python 2 version of the pip package manager, which in turn depends on the Python 2.7 package and thus will install Python 2.7.
Which means from this point on, you have two Python versions installed on the system, with two Python VM executables, python and python3, and two pip executables, pip and pip3.
It is not clear why you install Python 2.7 and python-pip on line 19 when you have already installed Python 3.10 and python3-pip on line 8. Nor is it clear why you install BioPython using pip, i.e. the Python 2 version instead of pip3, i.e. the Python 3 version.
I would not install Python 2 at all, since it has not been maintained or supported for several years. I would also not use Ubuntu 18.04, which will be out of standard support in 4 months, unless you are paying for the Extended Security Maintenance. The latest Long-Term Support version of Ubuntu is 22.04.1 which has standard support until April 2027 and extended support until April 2032.

pip install: metadata-generation-failed in docker

This is my Dockerfile:
FROM alpine:3.14
# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add python3-dev # for python3.x installs
RUN apk add musl-dev
RUN apk add gcc
RUN mkdir -p /usr/src/tap-stashstock
RUN mkdir -p /usr/singer
WORKDIR /usr/src/tap-stashstock
ADD . /usr/src/tap-stashstock
ADD singer /usr/singer
RUN pip3 install --upgrade .
This works and then I run docker run -it stashstock-to-bigquery pip3 install target-bigquery which results in this error
Collecting grpcio<2.0dev,>=1.38.1
Downloading grpcio-1.44.0.tar.gz (21.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.4/21.4 MB 3.9 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-4wuwnk4b/grpcio_429c1ed72b4244a0a71ac7e9f1ec81c6/setup.py", line 256, in <module>
if check_linker_need_libatomic():
File "/tmp/pip-install-4wuwnk4b/grpcio_429c1ed72b4244a0a71ac7e9f1ec81c6/setup.py", line 203, in check_linker_need_libatomic
cpp_test = subprocess.Popen([cxx, '-x', 'c++', '-std=c++11', '-'],
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'c++'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
What am I missing from my Dockerfile?
This error may for not having a C/C++ compiler.
Try install gcc and build-essensial before pip installation.
Please follow the steps given in
https://github.com/grpc/issues/24556

setuptools is on v3.3 inside Dockerfile but actually is on v20.7.0

I'm running the following commands inside Ubuntu 16.04:
git clone git#github.com:liveblog/liveblog.git
cd liveblog
docker build .
This gives me the following output:
[.....]
Downloading/unpacking jmespath>=0.7.1,<1.0.0 (from boto3>=1.1.4,<1.5->Superdesk-Core->-r /tmp/requirements.txt (line 10))
Downloading jmespath-0.9.3-py2.py3-none-any.whl
Downloading/unpacking cryptography>=2.1.4 (from pyOpenSSL->flask-sentinel>=0.0.4,<0.1->Superdesk-Core->-r /tmp/requirements.txt (line 10))
Running setup.py (path:/tmp/pip_build_root/cryptography/setup.py) egg_info for package cryptography
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/cryptography/setup.py", line 28, in <module>
"cryptography requires setuptools 18.5 or newer, please upgrade to a "
RuntimeError: cryptography requires setuptools 18.5 or newer, please upgrade to a newer version of setuptools
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/cryptography/setup.py", line 28, in <module>
"cryptography requires setuptools 18.5 or newer, please upgrade to a "
RuntimeError: cryptography requires setuptools 18.5 or newer, please upgrade to a newer version of setuptools
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/cryptography
Storing debug log for failure in /root/.pip/pip.log
The command '/bin/sh -c cd /tmp && pip3 install -U -r /tmp/requirements.txt' returned a non-zero code: 1
Checking the installed version of setuptools via pip3 list and pip list returns:
[...]
setuptools (20.7.0)
[...]
I added the following line into the Dockerfile right before RUN cd /tmp && pip3 install -U -r /tmp/requirements.txt:
RUN pip3 list
and then when I run docker build . again I get the following output:
Step 20/27 : RUN pip3 list
---> Running in 391e5e5e490b
chardet (2.2.1)
colorama (0.2.5)
html5lib (0.999)
lxml (3.3.3)
pip (1.5.4)
requests (2.2.1)
setuptools (3.3)
six (1.5.2)
urllib3 (1.7.1)
Why is setuptools now on v3.3 and how am I able to save this behavior?
I am assuming that you must have been checking setup tools on your host-machine, that says (20.7.0) , however it should have been upgraded inside Docker-Image. (Inside your docker images as you said it is : 3.3.
Try replacing your instructions with this one or may be anything that is more suitable.
#> RUN cd /tmp && pip3 install -U setuptools && pip3 list && pip3 install -U -r /tmp/requirements.txt
This will resolve the current issue that is related to setuptools version.

Failed to run Apache Singa after installation

Followed the instruction and installed Apache Singa v1.0.0 from the wheel successfully, but failed to run it below,
(singa) $ pip list | grep singa
singa (1.0.0)
(singa) $ python
> import singa
> ImportError: No module named '_singa_wrap'
(singa) $ find -name "*singa_wrap*"
singa_wrap.py
singa_wrap.pyc
_singa_wrap.so
Seemed something suspicious with Swig module extension. Any suggestions?
#EDIT
Verified that protobuf 2.6.1 already installed globally below,
(singa) $ python -c "from singa import _singa_wrap"
undefined symbol: _ZNK6google8protobuf7Message11GetTypeNameEv
$ ldd _singa_wrap.so
libprotobuf.so.9 => /usr/lib/x86_64-linux-gnu/libprotobuf.so.9
$ dpkg -S libprotobuf.so.9
libprotobuf9v5
$ apt-cache policy libprotobuf9v5
Installed: 2.6.1-1.3
#Solution
Singa starts dancing now after protobuf 2.6.1 being successfully installed locally on Ubuntu 16.04 below,
$ sudo apt-get install python-pip # gcc-5 required thus installed
$ sudo apt-get install gcc-4.8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
$ sudo update-alternatives --config gcc # to choose gcc-4.8
The rest then follows the answer #Wei below. Thanks again.
I think you can try the approaches in the first FAQ http://singa.apache.org/en/docs/installation.html#faq
In addition, you can check the dependent libs of _singa_wrap.so (go to /Python2.7/site-packages/singa/, and ldd _singa_wrap.so. If any library (e.g. cudnn or protobuf) is not found, then try to install it or export the library path.
There is a ticket for your issue https://issues.apache.org/jira/browse/SINGA-255.
Will update you once it is done.
Thanks.
UPDATE:
It seems your error is related to protobuf (could be caused by multiple versions of protobuf on your computer). Here is the solution,
Download protobuf (protobuf-2.6.1.tar.gz on github) and decompress the tar file
Install protobuf into /home//local/ by
./configure --prefix=/home/<yourname>/local
make && make install
echo "export LD_LIBRARY_PATH=/home/<yourname>/local/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc
pip uninstall singa
pip install <path to the wheel file>

How to build a kivy application using buildozer and the latest kivy?

Using buildozer I have successfully built and run an Android application.
Buildozer uses kivy-stable (1.7)
How do I build a kivy application using the latest kivy 1.8 ?
I noticed at
https://github.com/kivy/python-for-android/blob/master/recipes/kivy/recipe.sh the lines
VERSION_kivy=${VERSION_kivy:-stable}
URL_kivy=https://github.com/kivy/kivy/zipball/$VERSION_kivy/kivy-$VERSION_kivy.zip
Does this mean that only the kivy-stable version can be used with buildozer ?
Thanks
I can't remember if buildozer has a switch to use kivy master (1.8 is unreleased), but you can certainly make it work. Here's a few instructions assuming your shell is something bash-like.
First, create your own local kivy repository:
git clone https://github.com/kivy/kivy.git
Second, export the environment variable P4A_kivy_DIR to point at this directory. If this variable exists, python-for-android (including the one downloaded and used by buildozer) will use that directory to build kivy.
export P4A_kivy_DIR="$PWD/kivy$
echo $P4A_kivy_DIR
The second line should print out the directory of your newly cloned kivy.
You can then run buildozer. You might need to first delete the .buildozer file in your app dir, or more specifically some of the python-for-android components - easiest is just to do
rm -rf /path/to/your/app/.buildozer/android/platform/python-for-android
After that, just run buildozer and the python-for-android component should use your copy of kivy master.
If you want this behaviour to automatically work every time, you could put the export line in your .bashrc or some other suitable shell setup file. If you don't do this, you'll need to run the export line every time you create or replace a .buildozer directory.
Now (as on January, 2020) there is an easier option: just specify version in buildozer.spec, e.g.:
requirements = python3,kivy==2.0.0rc1
Google Colab!!!
go to this website: https://colab.research.google.com/
Step 1 : Create a new Note Book
Step 2 : add a new code
Step 3:add your main python file and kv file
Note: Make sure that your notebook is connected to runtime
Step 4:Copy and paste these codes in spreate code cells
!pip install buildozer
.
!pip install cython==0.29.19
.
!sudo apt-get install -y \
python3-pip \
build-essential \
git \
python3 \
python3-dev \
ffmpeg \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-ttf-dev \
libportmidi-dev \
libswscale-dev \
libavformat-dev \
libavcodec-dev \
zlib1g-dev
.
!sudo apt-get install -y \
libgstreamer1.0 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good
.
!sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev libffi6
.
!sudo apt-get install libffi-dev
.
!buildozer init
.
Make sure to rename your python file as main.py
and also upload all the images used in the programe(if used)
navigate to builder.spec file
uncomment and comment these following lines
add __version__ = 0.1 at the top of your main.py
Then
add these Code
!sudo apt install build-essential autoconf libtool
.
pip install --user -U colorama
.
pip install libtool
.
pip install testcase-automaker
.
pip install autoconf
Finally
add this code ...
This will build the apk
!buildozer -v android debug
This Worked for me
Hope this will work for all
Basically - you specify build related things in your buildozer.spec file.
Detailed how to - available on project page:
https://buildozer.readthedocs.io/en/latest/quickstart.html#init-and-build-for-android
In buildozer.spec you can define:
Requirements needed to build/ compile your project like:
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements =python3,kivy,kivymd==0.104.2,pillow==9.1.0,sqlite3
You shouldn't forget about Android permissions if needed for example:
# (list) Permissions
android.permissions =
READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE
Last thing in the specs is to define architecture for compiled file. For example:
# (int) Target Android API, should be as high as possible.
android.api = 30
And:
# (list) The Android archs to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
android.archs = armeabi-v7a, x86
Then terminal command to buildozer to compile:
$ buildozer -v android debug
You will end up with *.apk file that can be used on physical device (copy to the device, grant permissions to the file on the physical device) or in Android emulator (i.e. GenyMotion -> https://www.geeksforgeeks.org/how-to-set-up-an-emulator-for-vscode/).
If any troubles in build or live debugging you can connect to the emulator with adb, like:
$ adb logcat YOUR_DEVICE_IP > log.txt

Resources