Pyjnius import file file

Pyjnius allows you to create a python wrapper for Java classes, for example:

Hardware = autoclass('org.myapp.Hardware')

Is there a way to import an existing .jar file? What does the syntax look like?

+4
source share
2 answers

As an jarAndroid-only file , you need to add the jar file to your buildozer.spec file, for example

android.add_jars = java/myjar.jar

and in your application build

from kivy.utils import platform
...
if platform() == 'android':
    BlaClass = autoclass('java.bla.BlaClass')
...
+2
source

You can add the jar to CLASSPATH, then import pyjnius and use autoclass as usual :-):

import os
os.environ['CLASSPATH'] = "path/to/your.jar"

from jnius import autoclass


Bla = autoclass('bla.bla.BlaClass')
+5
source

Source: https://habr.com/ru/post/1524897/


All Articles