Skip to content

Fix android module JAVA_NAMESPACE and JNI_NAMESPACE with unicode #1475

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

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pythonforandroid/recipes/android/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def prebuild_arch(self, arch):
th = '#define {} {}\n'
tpy = '{} = {}\n'

bootstrap = bootstrap_name = self.ctx.bootstrap.name
bootstrap = bootstrap_name = self.ctx.bootstrap.name.decode('utf-8')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 1032, in <module>
    main()
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 1028, in main
    ToolchainCL()
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 550, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 149, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/toolchain.py", line 188, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/build.py", line 635, in build_recipes
    recipe.prebuild_arch(arch)
  File "/home/andre/workspace/EtherollApp/.buildozer/android/platform/python-for-android-new-toolchain/pythonforandroid/recipes/android/__init__.py", line 33, in prebuild_arch
    bootstrap = bootstrap_name = self.ctx.bootstrap.name.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

😢

Copy link
Contributor Author

@KeyWeeUsr KeyWeeUsr Nov 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is due to the Dockerfile using Python 2, therefore it worked for me on the device with py3 but it fails when you want to compile with py3 on the host. I think we should fully switch to unicode literals otherwise in case something is generated like variable = 'value' it'll always split to bytes on py2 and unicode on py3 and we either start checking each damn occurrence of this schrodinger's string or do this:

>>> b'x'.encode('utf-8').decode('utf-8')  # py2 + py3 bytes only
u'x'
>>> u'x'.encode('utf-8').decode('utf-8')  # py3 only
u'x'

and get kicked by anything that is not ASCII encodable.

Perhaps a fix for this would be to remove the decode() and enforce self.ctx.bootstrap.name to be always unicode with an assert.

Copy link
Member

@AndreMiras AndreMiras Nov 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in to fully switch since it's one step further the migration to python3 and we can still make it compatible with python2 with e.g. unicode_literals from future.
Edit: link to some a bug report kivy/buildozer#756

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by #1512

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a proper fix with future package, but could not test it because of gradle crash. Will do asap.

is_sdl2 = bootstrap_name in ('sdl2', 'sdl2python3', 'sdl2_gradle')
is_pygame = bootstrap_name in ('pygame',)
is_webview = bootstrap_name in ('webview',)

if is_sdl2 or is_webview:
if is_sdl2:
bootstrap = 'sdl2'
java_ns = 'org.kivy.android'
jni_ns = 'org/kivy/android'
java_ns = u'org.kivy.android'
jni_ns = u'org/kivy/android'
elif is_pygame:
java_ns = 'org.renpy.android'
jni_ns = 'org/renpy/android'
Expand Down
6 changes: 3 additions & 3 deletions pythonforandroid/recipes/android/src/android/_android.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ api_version = autoclass('android.os.Build$VERSION').SDK_INT
version_codes = autoclass('android.os.Build$VERSION_CODES')


python_act = autoclass(JAVA_NAMESPACE + '.PythonActivity')
Rect = autoclass('android.graphics.Rect')
python_act = autoclass(JAVA_NAMESPACE + u'.PythonActivity')
Rect = autoclass(u'android.graphics.Rect')
mActivity = python_act.mActivity
if mActivity:
# PyGame backend already has the listener so adding
# one here leads to a crash/too much cpu usage.
# SDL2 now does noe need the listener so there is
# SDL2 now does not need the listener so there is
# no point adding a processor intensive layout listenere here.
height = 0
def get_keyboard_height():
Expand Down