Pyjnius on Python3

451 views
Skip to first unread message

Geekademy

unread,
Apr 21, 2017, 8:22:34 PM4/21/17
to kivy-...@googlegroups.com
I've been using Python3.5 to create a Kivy app.

Now I need Pyjnius, but it crashes on "from jnius import autoclass" with:

>>> from jnius import autoclass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/jnius/__init__.py", line 13, in
<module>
from .reflect import * # noqa
File "/usr/local/lib/python3.5/dist-packages/jnius/reflect.py", line 14, in
<module>
class Class(with_metaclass(MetaJavaClass, JavaClass)):
File "/usr/lib/python3/dist-packages/six.py", line 808, in __new__
return meta(name, bases, d)
File "jnius/jnius_export_class.pxi", line 43, in jnius.MetaJavaClass.__new__
(jnius/jnius.c:17227)
File "jnius/jnius_export_class.pxi", line 65, in
jnius.MetaJavaClass.resolve_class (jnius/jnius.c:17623)
File "jnius/jnius_env.pxi", line 11, in jnius.get_jnienv (jnius/jnius.c:3422)
File "jnius/jnius_jvm_dlopen.pxi", line 90, in jnius.get_platform_jnienv
(jnius/jnius.c:3350)
File "jnius/jnius_jvm_dlopen.pxi", line 50, in jnius.create_jnienv
(jnius/jnius.c:2722)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 0: invalid
continuation byte

Seen here: https://github.com/kivy/pyjnius/issues/183

How does one go about fixing this? Unfortunately I've never used Cython, so
uncertain how it interacts with it.

Cheers,

Alexander Taylor

unread,
Apr 23, 2017, 7:56:18 AM4/23/17
to Kivy users support
Pyjnius works with python3 on Android, so maybe this is a desktop-specific issue. Are you targeting Android in particular?

Alexander Taylor

unread,
Apr 23, 2017, 8:01:15 AM4/23/17
to Kivy users support
I've just successfully tested pyjnius with python3.6 on desktop linux.
How did you install pyjnius?
> --
> 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/F5X9MWW5sm4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


signature.asc

Geekademy

unread,
Apr 23, 2017, 12:37:22 PM4/23/17
to kivy-...@googlegroups.com
I did this:

sudo -H pip3.5 install pyjnius

As you're getting at I did try to import it first on my desktop, and then
googled the error. I should try to deploy and see what happens there.
--
-Mike


-------------------------------------------------------------
Mike Miller Earth, Sol, Orion Arm, Milky Way, VSC

Geekademy

unread,
Apr 24, 2017, 5:59:19 PM4/24/17
to kivy-...@googlegroups.com, alexander...@gmail.com
Thanks for your help. I'm having a number of small issues, not sure of the best
way to handle them.

I'm trying to hide the navigation bar on android, see this gist:

https://gist.github.com/rnixx/add38d808b5a8ad73947

First, the module crashes on Linux with UnicodeDecodeError. I understand now it
doesn't run there, but the module shouldn't crash with an obscure error on
import. I added another exception handler to handle that.

Next, noticed that I was getting a "android" module ImportError, so had to add
it to my requirements in the buidozer.spec. Will this make it hard to use for
iOS in the future? So I built/installed the android module.

Next I get this crash message:

I/python (22386): Android: API level 19
I/python (22386): Android: set hide_menu.

W/dalvikvm(22386): JNI WARNING: static fieldID 0x4194a558 not valid for class
Lorg/renpy/android/PythonActivity; (GetStaticObjectField)
W/dalvikvm(22386): base=0x429acf60 count=0
W/dalvikvm(22386): in
Lorg/jnius/NativeInvocationHandler;.invoke0:(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;
(GetStaticObjectField)
I/dalvikvm(22386): "main" prio=5 tid=1 RUNNABLE
I/dalvikvm(22386): | group="main" sCount=0 dsCount=0 obj=0x41644ca8
self=0x4157e408
I/dalvikvm(22386): | sysTid=22386 nice=0 sched=0/0 cgrp=apps handle=1074864468
I/dalvikvm(22386): | state=R schedstat=( 533852336 271809870 1223 ) utm=35
stm=18 core=1
I/dalvikvm(22386): at org.jnius.NativeInvocationHandler.invoke0(Native Method)
I/dalvikvm(22386): at
org.jnius.NativeInvocationHandler.invoke(NativeInvocationHandler.java:26)
I/dalvikvm(22386): at $Proxy0.run(Native Method)
I/dalvikvm(22386): at android.os.Handler.handleCallback(Handler.java:733)
I/dalvikvm(22386): at android.os.Handler.dispatchMessage(Handler.java:95)
I/dalvikvm(22386): at android.os.Looper.loop(Looper.java:136)
I/dalvikvm(22386): at android.app.ActivityThread.main(ActivityThread.java:5001)
I/dalvikvm(22386): at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(22386): at java.lang.reflect.Method.invoke(Method.java:515)
I/dalvikvm(22386): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
I/dalvikvm(22386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
I/dalvikvm(22386): at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(22386):
E/dalvikvm(22386): VM aborting


Not sure what to do here? Thanks again.

Geekademy

unread,
Apr 24, 2017, 6:25:19 PM4/24/17
to Alexander Taylor, kivy-...@googlegroups.com
Thanks.

The android module is used by the gist, apparently to confine the code to the ui
thread. Can I ignore/remove that?

The code no longer crashes, but unfortunately does not hide the nav bar (android
back and home buttons).


On 2017-04-24 15:05, Alexander Taylor wrote:
> You don't need the android module if you compile with SDL2 (which is the
> default using the current python-for-android toolchain). If Kivy works
> but has a message about android in the log, you can ignore the message,
> it's not actually an error.
>
> For the crash, some code that you're running is trying to autoclass
> org.renpy.android.PythonActivity, but it needs to autoclass
> org.kivy.android.PythonActivity instead.
Reply all
Reply to author
Forward
0 new messages