How to include custom Java classes in python kivy project using pyjnius

311 views
Skip to first unread message

Adrian Flores

unread,
Apr 28, 2023, 10:49:12 PM4/28/23
to Kivy users support
Hi, just like the caption says, I am trying to include some java classes that I created. I'm getting a 'java.lang.ClassNotFoundException' error when I try to instantiate the class like so:

MyService = autoclass('com.example.servicetester.MyService')
service = MyService()

My .java, .class, .jar files are in the same directory as my main.py, and
these are the lines in my buildozer.spec to include the classes in the .apk: android.add_jars_whitelist = MyService.jar, MainActivity.jar android.add_src = AndroidManifest.xml

I appreciate any tips, thanks in advance!

Robert

unread,
Apr 29, 2023, 3:21:07 AM4/29/23
to Kivy users support

You can't specify your own manifest, only modify the automatic one with various options in buildozer.spec

You can't specify your own MainActivity, that will be the automatic PythonActivity ( Python and  main.py, and...)
You can add your own activity by using Pyjnius to start an Intent.

You can't create your own options in buildozer.spec, only the predefined ones are available.

I don't think you start a service like that, because in this context a service is a Python script
There is some talk of adding support for native (Java) services, I'm not certain of the current implementation status.

#1 tip, don't guess, read the documentation.
Reply all
Reply to author
Forward
0 new messages