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

unicode error during startup (python3, numpy, opencv) - patch included #1691

Closed
zworkb opened this issue Feb 7, 2019 · 6 comments
Closed

Comments

@zworkb
Copy link
Contributor

zworkb commented Feb 7, 2019

when building an app with python3, numpy and opencv I get a runtime error (Android 7.0, latest p4a):

python  :    File "/home/phil/dev/kivy/cvtest/.buildozer/android/platform/build/build/python-installs/cvtest400/android/__init__.py", line 8, in <module>
python  :    File "android/_android.pyx", line 178, in init android._android
python  :  TypeError: must be str, not bytes

this is due to a concatenation of two strings of which one is not guaranteed to be unicode. This can be repaired by applying the following patch:

diff --git a/pythonforandroid/recipes/android/src/android/_android.pyx b/pythonforandroid/recipes/android/src/android/_android.pyx
index d332eed..4d77ebc 100644
--- a/pythonforandroid/recipes/android/src/android/_android.pyx
+++ b/pythonforandroid/recipes/android/src/android/_android.pyx
@@ -174,8 +174,8 @@ from jnius import autoclass, PythonJavaClass, java_method, cast
 api_version = autoclass('android.os.Build$VERSION').SDK_INT
 version_codes = autoclass('android.os.Build$VERSION_CODES')
 
-
-python_act = autoclass(JAVA_NAMESPACE + u'.PythonActivity')
+java_namespace = JAVA_NAMESPACE.decode() if isinstance(JAVA_NAMESPACE, bytes) else JAVA_NAMESPACE
+python_act = autoclass(java_namespace  + u'.PythonActivity')
 Rect = autoclass(u'android.graphics.Rect')
 mActivity = python_act.mActivity
 if mActivity:
@tshirtman
Copy link
Member

getting the same issue here, will try the patch asap.

@AndreMiras
Copy link
Member

Fixed on master, thanks for the help guys 👍

@MathematicMarble
Copy link

applying the patch where?
Help please , im so lost..

@el3
Copy link

el3 commented May 29, 2019

It's fixed in master it says in the post 2 months ago.

@MathematicMarble
Copy link

I get the same error even though its fixed?

@leematthewshome
Copy link

I am seeing the same error myself.

06-24 20:21:15.753 1064 1083 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/android/init.py", line 8, in
06-24 20:21:15.753 1064 1083 I python : File "android/_android.pyx", line 162, in init android._android
06-24 20:21:15.754 1064 1083 I python : TypeError: must be str, not bytes
06-24 20:21:15.754 1064 1083 I python : Python for android ended.

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

6 participants