JNIUS-PYTHON3 is not defined error when debugging buildozer android - android

I have a Kivy app I am trying to package into an android app using Buildozer. I have installed Pyjnius and Cython but I still get a JNIUS_PYTHON3 is not defined error when it unpacks Cython in the buildozer -v android debug command. Does anyone know how I can fix this? Thanks!

I was seeing the same error. In the folder
.buildozer/android/platform/build-armeabi-v7a/build/other_builds/pyjnius-sdl2/armeabi-v7a__ndk_target_21/pyjnius/jnius
I created a config.pxi file which contained the following lines
DEF JNIUS_PLATFORM = 'android'
DEF JNIUS_PYTHON3 = 'true'
This got me past the error message you mentioned, although I am still stuck on further errors.

Having now gotten my app to compile to an APK file using Buildozer, I feel that my previous answer was just masking an underlying issue of some dependencies not being correctly installed. Going back through my BASH history, the steps I followed can be summarised as...
The initial setup
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python setup.py install
Then create a folder within the main buildozer folder to keep the python and kivy files associated with my app
mkdir MyAndroidApp
cd MyAndroidApp/
cp __My_Source_Files__ ./
buildozer init
nano buildozer.spec # Edit some basic settings here
buildozer android debug deploy
When that build process failed, I went through a series of steps to check various dependencies. Some of the following steps appear to me to do basically the same thing, so they are probably not all required, but this is a full list of the various things I tried along the path to eventual success.
sudo apt install libffi-dev
sudo apt install python3-setuptools
sudo apt install libssl-dev
sudo apt install python3-pip
sudo apt install python-pip
pip3 install --user --upgrade Cython==0.29.19 virtualenv
pip3 install --user --upgrade pyjnius
pip3 install --user --upgrade setuptools
pip install Cython
pip3 install setuptools
I was then able to use the following commands to get a successful build
buildozer android clean
buildozer android debug deploy
If you are seeing that error, then I think the correct place to start is to look at the dependencies that are being complained about in the various error messages and double check that everything is installed correctly.
In the end, it worked for me, and I hope that these notes prove some use to you in sorting through your issues as well. Good luck.

Related

How to convert .py to APK file using Python for Android on Windows?

I am working on Kivy framework. I have some sample of Kivy which has .py extension which I want to convert to .apk files. I want to check whether these working on Android or not.
I have some information about this. We have two ways to build an .apk file:
Using Python for Android,
Using Buildozer.
But Buildozer is only supported on Linux. I thought it has some problems on Windows.
Hence, I want to use Python for Android. But I have no idea how to approach this one.
Have anyone tried this one.
You can use VirtualBox Get it here and any Linux Distribution such as Ubuntu Ubuntu.
After installing Ubuntu to your Virtualbox you can use below commands:
Run these commands on Terminal
sudo apt install git
sudo apt install python3-pip
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python3 setup.py install
Now, navigate to your project directory using cd (or) goto your Project directory, RightClick -->select 'Open in terminal' and in Terminal type:
buildozer init
Above Command creates a buildozer.spec file controlling your build configuration. You should edit it appropriately with your app name, file extensions used in the project, external dependencies etc. After configuring your buildozer.spec fille run below commands:
sudo apt update
sudo apt install -y git zip unzip openjdk-8-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev
pip3 install --user --upgrade Cython==0.29.19 virtualenv # the --user should be removed if you do this in a venv
sudo pip3 install cython #(optional) If you got any Error as Cython not Found, use this
which buildozer
Above command is to check buildozer was added to your PATH), If no results found, add the following line at the end of your ~/.bashrc file--> export PATH=$PATH:~/.local/bin/
buildozer appclean
buildozer android debug
If you are asked for any licence agreement type y and click Enter
Once this process completes you will get a .apk file in your project directory bin/yourapp.apk
Kivy themselves used to have a virtual machine prepared with everything installed ready to go!
For some reason they stopped, now you have to install the Virtual Machine yourself.
You can see how to do this here
here is a link you can find everything that is related to getting .Apk files
https://python-for-android.readthedocs.io/en/latest/quickstart/#usage

Tool unzip is missing, buildozer, kivy

I am new to kivy, and try to build an app for android using kivy.
When i was creating an apk for the app
buildozer android debug
with log_level=2
it shows:
Tool unzip is missing
Command failed: ./distribute.sh -m "kivy" -d "kivytut"
Buildozer failed to execute the last command
The error might be hidden in the log above this error
Please read the full log, and search for it before
raising an issue with buildozer itself.
In case of a bug report, please add a full log with log_level = 2
I'm unable to find any tool called upzip for buidozer(python-for-android) on the internet.
Help.
install unzip using:
sudo apt-get install unzip
moreover following are the tools that must be installed:
git
ant
python2
cython (can be installed via pip)
a Java JDK (e.g. openjdk-7)
zlib (including 32 bit)
libncurses (including 32 bit)
unzip
virtualenv (can be installed via pip)
ccache (optional)
These are several dependencies for python-for-android

Installation is not happening according to Docker file

I am running a calabash-android test using docker. When I build the container with my docker file it seems like nothing executing except the first line. When I check whether ruby installed or not it shows the ruby version. Apart from that nothing is working. I am adding the docker file structure here.
############################################################
# Docker file to run Calabash for android automation testing.
############################################################
FROM ruby:2.1-onbuild
# install Android SDK dependencies
RUN apt-get install openjdk-7-jdk
# Install android sdk
RUN wget http://dl.google.com/android/android-sdk_r23-linux.tgz
RUN tar -xvzf android-sdk_r23-linux.tgz
RUN mv android-sdk-linux /usr/local/android-sdk
RUN rm android-sdk_r23-linux.tgz
# Install Android tools
RUN echo y | /usr/local/android-sdk/tools/android update sdk --filter platform,tool,platform-tool,extra,addon-google_apis-google-19,addon-google_apis_x86-google-19,build-tools-19.1.0 --no-ui -a
#install calabash-android
RUN gem install calabash-android
ENV ANDROID_HOME /usr/local/android-sdk
ENV ANDROID_SDK_HOME $ANDROID_HOME
ENV PATH $PATH:$ANDROID_SDK_HOME/tools
ENV PATH $PATH:$ANDROID_SDK_HOME/platform-tools
ENV JAVA_HOME /usr/lib/jvm/java-7-oracle
I have followed this link to implement the Docker file. Since this is for the first time I am setting up docker for android haven't the faintest idea whether it is proper or not. Someone please help to fix the issue. All kinda helps are appreciated.
I get this response for the docker build
Step 0 : FROM ruby:2.1-onbuild
# Executing 4 build triggers
Trigger 0, COPY Gemfile /usr/src/app/
Step 0 : COPY Gemfile /usr/src/app/ Gemfile: no such file or directory
First, as long as the docker build does not execute all the steps, it is perfectly expected to not see anything installed.
Second, the ONBUILD directives from the ruby:2.1-onbuild are made to complete the image when building a new one from said image.
As I mention before, you can try first using
FROM ruby:2.3.0
That does not require extra onbuild trigger.

Kivy Python For Android Installation And App Deployment

So I could finally get a decent output in a shell about Kivy Python-For-Android installation and distro build. The thing is that I cannot seem to get the compass example to work at all. A force close is activated right after running the app.
I'm using the latest toolchain and the old doesn't seems to work... An error about old chain not supported any more.
The thing is that I'm using the latest version of SDK and NDK. The documentation ask for android API 14 but it's not found on the android manager repository. All APIs are present but not API 14 so I use API 17.
The installation script I manage to put together with things out of the current doc to make it work on: Ubuntu 15.10 x64
#### Tested On x64 System ####
# Enable Restricted, Universe & Multiverse Repositories
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu$(lsb_release -sc) main universe restricted multiverse"
# Add x86 Packets
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y build-essential ccache git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-7-jdk unzip ant python-pip cython autoconf libtool
sudo pip install virtualenv
git clone https://github.com/kivy/python-for-android.git
cd python-for-android
python setup.py install
export ANDROIDSDK="/media/$(logname)/EXTSave/android-sdk-linux"
export ANDROIDNDK="/media/$(logname)/EXTSave/android-ndk-r11b"
export ANDROIDAPI=17
export ANDROIDNDKVER=11
# EXTSave is an HDD Partition
python-for-android apk --private /media/$(logname)/EXTSave/compass --requirements=python2 --package=org.pirate.kaizoku --name="Kaizoku" --version=0.1
How can I compile an example or something? Is there something wrong?
Since I'm no professional programmer I forgot/didn't know how to check the logs but after more searching I finally found my error! The program was not not able to import the kivy framework. I forgot to add it in:
python-for-android apk --private /media/$(logname)/EXTSave/compass --requirements=python2,sdl,kivy --package=org.pirate.kaizoku --name="Kaizoku" --version=0.1
Since the original installation code is working I will make some changes for automation and leave it here for future reference for faster approach to the framework.
For future problems use the logs to check any problems:
python-for-android logcat

ImportError: No Module named bz2 for Python 2.7.3 [duplicate]

I'm using Python 2.7.2 on Ubuntu 11.10. I got this error when importing the bz2 module:
ImportError: No module named bz2
I thought the bz2 module is supposed to come with Python 2.7. How can I fix this problem?
EDIT: I think I previously installed Python 2.7.2 by compiling from source. Probably at that point I didn't have libbz2-dev and so the bz2 module is not installed. Now, I'm hoping to install Python2.7 through
sudo apt-get install python2.7
But it will say it's already installed. Is there a way to uninstall the previous Python2.7 installation and reinstall?
I meet the same problem, here's my solution.
The reason of import error is while you are building python, system couldn't find the bz2 headers and skipped building bz2 module.
Install them on Ubuntu/Debian:
sudo apt-get install libbz2-dev
Fedora:
sudo yum install bzip2-devel
and then rebuild python
comes from another answer
#birryree's answer helps to back to the system's original python.
Okay, this is much easier to understand in answer form, so I'll move what I would write in my comment to this answer.
Luckily for you, you didn't overwrite the system version of python, as Ubuntu 11.10 comes with 2.7.2 preinstalled.
Your python binaries (python and python2.7) are located in /usr/local/bin, which is a directory where user-specific stuff is usually installed. This is fine, it means your system python is still there.
First, just try to run the system python. Type this from the command line:
/usr/bin/python -c "import bz2; print bz2.__doc__"
This should print out something like this:
λ > /usr/bin/python -c "import bz2; print bz2.__doc__"
The python bz2 module provides a comprehensive interface for
the bz2 compression library. It implements a complete file
interface, one shot (de)compression functions, and types for
sequential (de)compression.
If so, means you're fine.
So you just have to fix your PATH, which tells the shell where to find commands. /usr/local/bin is going to have priority over /usr/local, so there are some ways to fix this, in order of difficulty/annoyance/altering your system:
Remove the symlink python from /usr/local/bin
This will make it so that when you type python, it should go back to executing /usr/bin/python, which is an alias for the system's python 2.7.2.
sudo rm /usr/local/bin/python
Move /usr/bin to have higher precedence in the PATH
Might not be desirable if you already have stuff in /usr/local/bin that should have precedence over /usr/bin, but I'm adding this for completeness.
In your shell profile (not sure what Ubuntu's default is, but I'm using ~/.bash_profile, you can do this:
export PATH=/usr/bin:$PATH
Remove your python install
This is extreme and the first option I presented should be your first option.
Do you really need your own version of Python? If you want isolated python environments you probably really want virtualenv. You can probably remove yours unless there's a reason not to.
It's going to be a little annoying though, but basically:
Remove the python and python2.7 and pythonw and pythonw2.7 commands from /usr/local/bin.
Remove /usr/local/lib/python/2.7.2
This part is not complete because I forget what else there is.
In case, you must be used python2.7, you should run: (Centos 6.4)
sudo cp /usr/lib64/python2.6/lib-dynload/bz2.so /usr/local/lib/python2.7/
Maybe it will helps someone:
apt-get install libbz2-dev # for bz2
apt-get install libssl-dev # for _ssl
apt-get install libsqlite3-dev # for sqlite
apt-get install libreadline6-dev # for readline, _curses, _curses_panel
For Ubuntu/Debian:
sudo apt-get install libbz2-dev
For Fedora:
sudo yum install bzip2-devel
And then recompile the python and install it.
matocnhoi's answer works for me in centOS
sudo cp /usr/lib64/python2.6/lib-dynload/bz2.so /usr/local/lib/python2.7/
and I used virtualenv, so the command is
sudo cp /usr/lib64/python2.6/lib-dynload/bz2.so ../../../env/lib/python2.7/
I used a symlink between /usr/lib64/python2.6/lib-dynload/bz2.so /usr/local/lib/python2.7/lib-dynload/
Worked fine for me...
Make sure you bz2 installed, run sudo yum install bzip2-devel.
Centos 6
sudo cp /usr/lib64/python2.6/lib-dynload/bz2.so /python_install_path/lib/python2.7
Centos 7
sudo cp /usr/lib64/python2.7/lib-dynload/bz2.so /python_install_path/lib/python2.7
python_install_path usually is /usr/local/lib/python2.7/, you need replace that if you install python in a another path.
If your bz2 in /usr/lib64/python2.7/lib-dynload/ is named as: "bz2.x86_64-linux-gnu.so", remember to rename it to bz2.so when copying it to your path or it may not be correctly sourced:
cp /usr/lib64/python2.6/lib-dynload/bz2.x86_64-linux-gnu.so /python_install_path/lib/python2.7/bz2.so
I had the same problem with Python 2.17.15 and pyenv on Ubuntu. System python from /usr/bin/python worked fine. In my case it helped to install libbz2-dev and then to reinstall python 2.7.15:
sudo apt-get install libbz2-dev
pyenv uninstall 2.7.15
pyenv install 2.7.15

Categories

Resources