kivypyjnius

Kivy: what package name should I use for .jar files added with add_jars?


1) In my kivy's project I created \platforms\android\test.java with following content:

class Test {
    public int test() {
        return 300;
    }
}

And compiled it to .jar file (in same directory).

2) In buildozer.spec I added line:

android.add_jars = %(source.dir)s/platforms/android/*.jar

3) In projects main.py I'm trying to use it:

import logging
from kivy.utils import platform

if platform == "android":
    from jnius import autoclass, cast

    Test = autoclass('test.Test')
    logging.info(Test().test())

4) apk builds fine, but I get error:

jnius.jnius.JavaException: Class not found 'test/Test'

I assume problem with package name I used autoclass('test.Test'). What name should I use to make things work?


Solution

  • Instead of adding .jar file it's easier to add java source file that p4a will handle to be used on Android.

    1) We have file

    /java_folder/some/test.java
    

    with following content:

    package some;
    
    class Test {
        public int test() {
            return 300;
        }
    }
    

    2) In buildozer.spec we add:

    android.add_src = %(source.dir)s/java_folder/
    

    3) In projects:

    autoclass('some.Test')
    

    works just fine.