Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str.decode() issue again for Python 3 #1749

Closed
chippyash opened this issue Mar 11, 2019 · 10 comments
Closed

str.decode() issue again for Python 3 #1749

chippyash opened this issue Mar 11, 2019 · 10 comments

Comments

@chippyash
Copy link

Versions

  • Python: 3.7
  • OS: Ubuntu 18.04
  • Kivy: current stable
  • Cython: 0.29.6

Description

This is very similar to kivy/buildozer#756 which turned out to be a python-for-android issue

L178 of .buildozer/android/platform/python-for-android/pythonforandroid/recipes/android/src/android/_android.pyx

has

python_act = autoclass(JAVA_NAMESPACE.decode('utf8') + u'.PythonActivity')

I changed it to

python_act = autoclass(JAVA_NAMESPACE + u'.PythonActivity')

did a buildozer clean, then built and deployed again and it worked.

So, as per original ticket, there are other places that need to be cleaned up perhaps for Python 3.

Command:

 buildozer android debug deploy
@darosior
Copy link
Contributor

darosior commented Mar 11, 2019

+1, I did a PR for this yesterday.
There are no other places, this is just #1747 that decode() a str.

@homdx
Copy link

homdx commented Mar 13, 2019

Hello.
Maybe it's some error:
(my test repo) build based by @Jonast p4a-build-spaces
https://github.com/homdx/flask-hello
log from phone

I/python  (29860): Android kivy bootstrap done. __name__ is __main__
I/python  (29860): AND: Ran string
I/python  (29860): Run user program, change dir and execute entrypoint
I/python  (29860): [INFO   ] [Logger      ] Record log in /data/data/com.example.test1/files/app/.kivy/logs/kivy_19-03-13_1.txt
I/python  (29860): [INFO   ] [Kivy        ] v1.11.0.dev0, git-Unknown, 20190313
I/python  (29860): [INFO   ] [Python      ] v3.7.1 (default, Mar 13 2019, 07:18:03) 
I/python  (29860): [Clang 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55
I/python  (29860): [INFO   ] [Factory     ] 184 symbols loaded
I/python  (29860): [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
I/python  (29860): [INFO   ] [Text        ] Provider: sdl2
I/python  (29860): Starting Flask app...
I/python  (29860): [INFO   ] [Window      ] Provider: sdl2
I/python  (29860): [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
I/python  (29860): [INFO   ] [GL          ] Backend used <sdl2>
I/python  (29860): [INFO   ] [GL          ] OpenGL version <b'OpenGL ES 3.1 build 1.4@3300288'>
I/python  (29860): [INFO   ] [GL          ] OpenGL vendor <b'Imagination Technologies'>
I/python  (29860): [INFO   ] [GL          ] OpenGL renderer <b'PowerVR Rogue G6200'>
I/python  (29860): [INFO   ] [GL          ] OpenGL parsed version: 3, 1
I/python  (29860): [INFO   ] [GL          ] Texture max size <8192>
I/python  (29860): [INFO   ] [GL          ] Texture max units <16>
I/python  (29860): [INFO   ] [Window      ] auto add sdl2 input provider
I/python  (29860): [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
I/python  (29860): [WARNING] [Base        ] Unknown <android> provider
I/python  (29860): [INFO   ] [Base        ] Start application main loop
I/python  (29860): [INFO   ] [GL          ] NPOT texture support is available
I/python  (29860): [INFO   ] [Base        ] Leaving application in progress...
I/python  (29860):  Traceback (most recent call last):
I/python  (29860):    File "/home/userhome/flask-hello/main.py", line 28, in <module>
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/app.py", line 855, in run
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/base.py", line 502, in runTouchApp
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/core/window/window_sdl2.py", line 724, in mainloop
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/core/window/window_sdl2.py", line 459, in _mainloop
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/base.py", line 337, in idle
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/clock.py", line 581, in tick
I/python  (29860):    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
I/python  (29860):    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
I/python  (29860):    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
I/python  (29860):    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/kivy/base.py", line 208, in remove_android_splash
I/python  (29860):    File "/home/userhome/.local/share/python-for-android/build/python-installs/unnamed_dist_1/android/__init__.py", line 8, in <module>
I/python  (29860):    File "android/_android.pyx", line 178, in init android._android
I/python  (29860):  AttributeError: 'str' object has no attribute 'decode'
I/python  (29860): Python for android ended.

@ghost
Copy link

ghost commented Mar 13, 2019

Maybe you still got an older version of p4a? You could try the p4a build spaces option --force-redownload-p4a or alternatively cleaning the Docker image. (without that option p4aspaces will per default let docker cache/not redownload p4a unless required, so you can work offline with previously launched environments)

@homdx
Copy link

homdx commented Mar 13, 2019

@Jonast hello)) No. If compile today and give are black screen at kivy app . You can reproduce with my repo (link upper)

(Cache in my repository, I will make later (after then I check application logs on phone).
You can rebuild (reproduce) without cache from my repo:
time docker build -t test --build-arg DISABLECACHE=something .
and give from docker *.apk and test it)

@homdx
Copy link

homdx commented Mar 13, 2019

@chippyash
It's is realy help!
But in my project: I will sea the "Hello World" on the screen phone, only I if (switch to another window) and if return again to kivy application. Why?(

Fix android/pythonforandroid/recipes/android/src/android/_android.pyx

has

python_act = autoclass(JAVA_NAMESPACE.decode('utf8') + u'.PythonActivity')
I changed it to

python_act = autoclass(JAVA_NAMESPACE + u'.PythonActivity')

@AndreMiras
Copy link
Member

Thanks for the report. This was fixed recently with #1748 and #1752
You need to update to master

@SmartWaddles
Copy link

SmartWaddles commented Mar 21, 2019

Thanks for the report. This was fixed recently with #1748 and #1752
You need to update to master

Hello there!
Fix with removing .decode() from python_act didn't solve the problem for me.
After I found via adb, that my apk crashes on startup with an error File "android/_android.pyx", line 178, in init android._android AttributeError: 'str' object has no attribute 'decode' , I've tried to delete .decode('utf-8') manually from _android.pyx source.
I've changed
python_act = autoclass(JAVA_NAMESPACE.decode('utf8') + u'.PythonActivity') to
python_act = autoclass(JAVA_NAMESPACE + u'.PythonActivity') but after that I've faced an error TypeError: must be str, not bytes at the same place.
So I've decided to wrap up JAVA_NAMESPACE to string:
python_act = autoclass(str(JAVA_NAMESPACE) + u'.PythonActivity') but after that I've got:
jnius.jnius.JavaException: Class not found b"b'org/kivy/android'/PythonActivity". Finally, I've just hardcoded this path instead of JAVA_NAMESPACE and voila, APK was launched successfully.
Should I change this path somewhere else instead of hardcoding it there? Or my fix is OK?
I just don't want to re-upload all the recipes and modules for the recipes - i think it will be necessary if I'll re-install p4a.

Sorry, I'm new here.

And, also, there is a problem, that Kivy Interface shows only after On/Off the Screen or re-opening app on device (not from the first time).

@ghost
Copy link

ghost commented Mar 21, 2019

@AndreMiras shouldn't it either be ".PythonActivity" without the u that forces a unicode string (so it's bytes/str on python 2 as normal, and unicode/str on python 3 as normal), or alternatively pyjnius changed to return uniformly always bytes (even under python 3) or always unicode (even under python 2)?

Seems the main issue is here that the u prefix assumes a uniform return type when there just isn't one, so either that u prefix or the current pyjnius behavior don't make sense

Edit: irrelevant, lol 😄

@ghost
Copy link

ghost commented Mar 21, 2019

@SmartWaddles I just checked, the latest master has no decode on this line you could remove. Also, JAVA_NAMESPACE should already be unicode from what I could see (on master). Do you use an older version? It might work fine if you just go to latest master instead of trying to fix this manually

@SmartWaddles
Copy link

@SmartWaddles I just checked, the latest master has no decode on this line you could remove. Also, JAVA_NAMESPACE should already be unicode from what I could see (on master). Do you use an older version? It might work fine if you just go to latest master instead of trying to fix this manually

Yes, I've used and older version. I fixed it manually successfully, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants