Landlubber
Landlubber

Reputation: 3

Cannot compile an APK using Buildozer

I'm trying to compile a python file into an APK using buildozer. After installing all dependencies (including SDK and NDK) and running buildozer android deploy run, I get the following error:

/home/caliph/.buildozer/android/platform/android-sdk
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 5 more
# Command failed: /home/caliph/.buildozer/android/platform/android-sdk/tools/bin/sdkmanager tools platform-tools
# 
# 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

My python code is a simple class in a file titled main.py:

__version__ = '1.1'

class MyNewClass:
    '''This is a docstring. I have created a new class'''
    pass

How can I overcome this problem and create an APK. Please help!

Upvotes: 0

Views: 1243

Answers (2)

Vin
Vin

Reputation: 11

You need to do use the jdk 8. I am using openjdk-8-jdk on linux.

you can toggle the jdk using: sudo update-alternatives --config java

On Top of that, in order to avoid some of the issues of jdk, we are going to use options for JVM

  1. open the sdkmanager file in a editor.
  2. find wherver DEFAULT_JVM_OPTIONS or similar var is defined. make it like this:

DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

and then clean your stuff with : buildozer android clean

and remake it.

Upvotes: 1

ikolim
ikolim

Reputation: 16031

Causes

The error was due to incompatibility between buildozer and Java version used. In Parrot OS, the default Java version is openJDK11.

Solution

  1. Install openJDK8: sudo apt install openjdk-8jdk
  2. Set JDK8 as the active version for java: sudo update-alternatives --config java
  3. Set JDK8 as the active version for javac: sudo update-alternatives --config javac

Ubuntu OS

With the new version of Buildozer v0.39, CrystaX is deprecated.

Upgrade Buildozer

Ubuntu / Linux - Python 3

pip3 install --upgrade buildozer

Ubuntu 18.04 (64-bit)

sudo pip install --upgrade cython==0.28.6
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386

Ubuntu 16.04 (64-bit)

sudo pip install --upgrade cython==0.21
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386

Upvotes: 1

Related Questions