Adding Jar to Android Kivy app

324 views
Skip to first unread message

Kevin Ollivier

unread,
Jan 13, 2015, 11:52:51 AM1/13/15
to kivy-...@googlegroups.com
Hey all,

As part of an app I'm working on, I need to embed a web browser and handle its loading callbacks. The sample code for loading android WebKit in Kivy works fine, but unfortunately the WebViewClient used for handling callbacks in android's WebView isn't an interface, but instead is a regular class that requires you to subclass it and override the sublcass methods to handle the callbacks. I didn't see any way to create a Java subclass in Python-land, so I thought I would handle this by creating a Java WebViewCallbacks interface along with a Java WebViewClient subclass that takes a WebViewCallbacks-compliant object on initialization, and calls its methods in the callback handler methods. Then I could (theoretically) use PythonJavaClass to implement the WebViewCallbacks interface in Python-land, and the WebViewClient subclass I assign to my WebView will send messages to that object.

Where I'm getting stuck is in having Python 'see' the classes I created. After creating the classes, I used jar cf to compile the Java sources and passed --add-jar /path/to/my/JarFile.jar to add them to the bundle. Everything completes successfully, and i see a message that my .jar file got put into classes.dex, but I suspect I don't know how to properly reference my Java classes in Python. I tried doing package org.myapp.pywebviewclient at the top of my Java source and then referencing it as org/myapp/pywebviewclient/PyWebViewClient and org/myapp/pywebviewclient/WebViewCallbacks, but I just get errors about those classes not being found.

Is there a way I can debug or inspect the Java code to know how I should be referencing it, or if it is indeed visible to kivy / jnius?

Thanks,

Kevin 


Sergey Cheparev

unread,
Jan 14, 2015, 5:28:54 AM1/14/15
to kivy-...@googlegroups.com
Hey,

why don't you use buildozer? Try this in buildozer spec or just take a look in buildozer what's done with this instruction:

android.add_src = bla.java


One suggestion more is that the way you import things should use something like 'org.domain.app', not just only 'org.app', but very probable.

вторник, 13 января 2015 г., 17:52:51 UTC+1 пользователь Kevin Ollivier написал:

Kevin Ollivier

unread,
Jan 14, 2015, 6:13:41 PM1/14/15
to kivy-...@googlegroups.com
Hi Sergey,

Thanks for your help! The reason I didn't use buildozer is that the docs say it runs only on Linux, and I'm building from a Mac. Is that no longer the case?

I did look at the buildozer script though, and it looks like it just takes the Java source and puts it in a src directory under the distribution. Updating my own little build script to do the same solved the problem! I am now getting the callbacks fired in my PythonJavaClass interface. I also took your advice and switched to the org.domain.app format for the imports. :)

Thanks,

Kevin

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/13LgfE07R8c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sergey Cheparev

unread,
Jan 15, 2015, 5:01:04 AM1/15/15
to kivy-...@googlegroups.com
Hey,

you're welcome! Buildozer is just a python package, so I think i should work also under OSX. Have you tried it?

Best,
Sergey

Thu Jan 15 2015 at 12:13:41 AM, Kevin Ollivier <kev...@theolliviers.com>:

Kevin Ollivier

unread,
Jan 15, 2015, 11:12:43 AM1/15/15
to kivy-...@googlegroups.com
Hey Sergey,

Not yet, I first want to throw together a prototype app to make sure I can do everything I need with Python for Android / Kivy, and then once that is done I'll give buildozer a try and see if I can use it to clean up the build system some. This is pretty much a nights and weekends project for me right now so I can't promise anything in the way of timeframes, but if I do run into any issues with buildozer on Mac, I'll post and/or file a ticket, and hopefully even put in a patch or two. :)

Thanks again for your help!

Kevin
Reply all
Reply to author
Forward
0 new messages