PythonJavaClass error on android 4*

176 views
Skip to first unread message

Alexandre Pollet

unread,
May 7, 2015, 12:58:26 PM5/7/15
to kivy-...@googlegroups.com
Implementing java interfaces works fine on android 5* (tested on Nexus devices), but not on android 4* (tested on Samsung devices).

The error:
W/ActivityThread(10057): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
I/python  (10057):    File "/home/alex/PycharmProjects/dttb/.buildozer/android/app/main.py", line 277, in build
I/python  (10057):    File "/home/alex/PycharmProjects/dttb/.buildozer/android/app/gplay.py", line 153, in __init__
I/python  (10057):    File "/home/alex/PycharmProjects/dttb/.buildozer/android/app/gplay.py", line 8, in __init__
I/python  (10057):    File "/home/alex/PycharmProjects/dttb/.buildozer/android/app/gplay.py", line 158, in _get_client
I/python  (10057):    File "/home/alex/PycharmProjects/dttb/.buildozer/android/app/gplay.py", line 84, in __init__
I/python  (10057):    File "jnius_proxy.pxi", line 31, in jnius.jnius.PythonJavaClass.__init__ (jnius/jnius.c:23787)
I/python  (10057):    File "jnius_proxy.pxi", line 177, in jnius.jnius.create_proxy_instance (jnius/jnius.c:25931)
I/python  (10057):    File "jnius_export_class.pxi", line 624, in jnius.jnius.JavaMethod.__call__ (jnius/jnius.c:19592)
I/python  (10057):    File "jnius_export_class.pxi", line 790, in jnius.jnius.JavaMethod.call_staticmethod (jnius/jnius.c:21434)
I/python  (10057):    File "jnius_utils.pxi", line 65, in jnius.jnius.check_exception (jnius/jnius.c:3514)
I/python  (10057):  jnius.jnius.JavaException: JVM exception occurred: com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks is not visible from class loader
I/python  (10057): Python for android ended.

The code:
class GoogleApiClientConnectionCallback(PythonJavaClass):
        __javainterfaces__ = ['com/google/android/gms/common/api/GoogleApiClient$ConnectionCallbacks',
                              'com/google/android/gms/common/api/GoogleApiClient$OnConnectionFailedListener']
        __javacontext__ = 'app'


It seems __javacontext__ is not correctly interpreted...but if i change to 'apptest' i have an error says that 'apptest' must be app or system (jnius_proxy.pxi l:188).

I don't understand what is the problem....can you help me ?

I have already have an app with the bug (https://play.google.com/store/apps/details?id=fr.dolmapps.dttb).
I use google play services to display leaderboard and send scores.

I was inspired by this application (https://play.google.com/store/apps/details?id=com.meltingrocks.kivy2048) made by tito (Mathieu Virbel) which works fine with android 4*...what i missed ? :)




Playxz Il Negro

unread,
Nov 15, 2015, 11:09:43 AM11/15/15
to Kivy users support, pollet.a...@gmail.com
Hi Alexandre,
Did you solve the problem?
I'm stuck on the same problem...
Can you help me?

Val

unread,
Aug 29, 2016, 10:08:25 AM8/29/16
to Kivy users support, pollet.a...@gmail.com
Hi,
I got exactly the samble error "interface not visible from class loader"
with android 6.0
Did someone solve this?

thanks

Nathan McCorkle

unread,
Aug 30, 2016, 3:05:57 AM8/30/16
to Kivy users support, pollet.a...@gmail.com
I'm also hitting this issue.
Here is the javadoc for the interface:

Here is the section of java that implements an interface override method, from the github project I am trying to use for reference on my Kivy project:
from kivy.app import App #for the main app
from kivy.uix.floatlayout import FloatLayout #the UI layout
from kivy.uix.label import Label #a label to show information
from kivy.uix.button import Button
from plyer import accelerometer #object to read the accelerometer
from kivy.clock import Clock #clock to schedule a method  
from kivy.uix.boxlayout import BoxLayout

#########

# 'autoclass' takes a java class and gives it a Python wrapper
from jnius import autoclass
# Constants = autoclass('com.htc.lib1.duallens.Constants')
from jnius import PythonJavaClass
from jnius import java_method
# OnCompletionListener = autoclass('com.htc.lib1.duallens.DualLens$OnCompletionListener')
DualLens = autoclass('com.htc.lib1.duallens.DualLens')
_File = autoclass('java.io.File')
Environment = autoclass('android.os.Environment')

# PythonActivity is provided by the Kivy bootstrap app in python-for-android
PythonActivity = autoclass('org.renpy.android.PythonActivity')
activity = PythonActivity.mActivity

filename = "dualLensSample.jpg";
filepath = '{}{}{}'.format(Environment.getExternalStorageDirectory().getAbsolutePath(), _File.separator, filename)

self.d = DualLens(activity, filepath)
class ac(PythonJavaClass):
__javainterfaces__ = ['com/htc/lib1/duallens/DualLens$OnCompletionListener']

#class onCompletion(OnCompletionListener):
# onCompletion(DualLens dualLens, int what, int extra, java.lang.String filePath)
@java_method('(com/htc/lib1/duallens/DualLens;I;I;java/lang/String;)V;')
def onCompletion(arg0, event, extra, path):
print '{} $$$ {}'.format(arg0, event)

self.d.setOnCompletionListener(ac())
self.d.prepare()


The error is coming up for the second-to-last line "self.d.setOnCompletionListener(ac())" when I try to instantiate the object:
08-29 23:52:29.402  4904  4924 I python  :  Traceback (most recent call last):
08-29 23:52:29.403  4904  4924 I python  :    File "/home/nathan/Projects/kivy_test/.buildozer/android/app/main.py", line 107, in <module>
08-29 23:52:29.405  4904  4924 I python  :    File "/home/nathan/Projects/kivy_test/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/app.py", line 802, in run
08-29 23:52:29.407  4904  4924 I python  :    File "/home/nathan/Projects/kivy_test/.buildozer/android/app/main.py", line 103, in build
08-29 23:52:29.408  4904  4924 I python  :    File "/home/nathan/Projects/kivy_test/.buildozer/android/app/main.py", line 88, in __init__
08-29 23:52:29.410  4904  4924 I python  :    File "jnius_proxy.pxi", line 31, in jnius.jnius.PythonJavaClass.__init__ (jnius/jnius.c:25663)
08-29 23:52:29.411  4904  4924 I python  :    File "jnius_proxy.pxi", line 183, in jnius.jnius.create_proxy_instance (jnius/jnius.c:27889)
08-29 23:52:29.412  4904  4924 I python  :    File "jnius_export_class.pxi", line 637, in jnius.jnius.JavaMethod.__call__ (jnius/jnius.c:21397)
08-29 23:52:29.414  4904  4924 I python  :    File "jnius_export_class.pxi", line 803, in jnius.jnius.JavaMethod.call_staticmethod (jnius/jnius.c:23238)
08-29 23:52:29.415  4904  4924 I python  :    File "jnius_utils.pxi", line 93, in jnius.jnius.check_exception (jnius/jnius.c:3765)
08-29 23:52:29.416  4904  4924 I python  :  jnius.jnius.JavaException: JVM exception occurred: interface com.htc.lib1.duallens.DualLens$OnCompletionListener is not visible from class loader



Also, this project has both a .jar file and a .so file which seem to contain references to the same class namespace (I don't know if that is the right term for Java, me coming from a Python background):
one of these:



The best I can think is buildozer/kivy/python-for-android is getting confused about the two different sources of class-namespace... but I'd love to hear a solution nonetheless!

Please and thanks!
Reply all
Reply to author
Forward
0 new messages