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

my python app doesn't work after converting it to an .apk file using buildozer #1642

Closed
Alikhosravi22 opened this issue Jul 24, 2023 · 2 comments

Comments

@Alikhosravi22
Copy link

Alikhosravi22 commented Jul 24, 2023

hi
i am new in coding and i have written a chat app using python. my app works in my pc but when i convert it to a .apk app using buildozer its connect botton doesn't work.
part of my buildozer.spec file
Title of your application
title = Eitaa
package.name = eitaa
package.domain = org.test
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
version = 0.1
requirements = python3,kivy,rsa

presplash.filename = %(source.dir)s/loading.png

icon.filename = %(source.dir)s/logo.png

orientation = portrait

osx.python_version = 3
osx.kivy_version = 1.9.1

fullscreen = 0

android.permissions = android.permission.INTERNET, (name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)

my main.py file
import kivy
import socket
import threading
import rsa
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

from kivy.clock import mainthread

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
public_key, privet_key= rsa.newkeys(1024)

class MyRoot(BoxLayout):
def init(self):
self.server_public_key=None
super(MyRoot, self).init()

@mainthread
def update_chat_text(self, message):
    self.chat_text.text += message + "\n"   

def send_message(self):
    client.send(rsa.encrypt(f"{self.nickname_text.text}: {self.message_text.text}".encode(), self.server_public_key))

def connect_to_server(self):
    if self.nickname_text != "":
        client.connect((self.ip_text.text, 9999))
        message = client.recv(1024).decode('utf-8')
        if message == "NICK":
            client.send(self.nickname_text.text.encode('utf-8'))
            self.server_public_key=rsa.PublicKey.load_pkcs1(client.recv(1024))
            client.send(public_key.save_pkcs1('PEM'))
            self.send_btn.disabled = False
            self.message_text.disabled = False
            self.connect_btn.disabled = True
            self.chat_text.height=325
            self.ip_text.disabled = True
            self.make_invisible(self.connection_grid)
            self.make_invisible(self.connect_btn)
            thread = threading.Thread(target=self.receive)
            thread.start()

def make_invisible(self, widget):
    widget.visible = False
    widget.size_hint_x = None
    widget.size_hint_y = None
    widget.height = 0
    widget.width = 0
    widget.text = ""
    widget.opacity = 0

def receive(self):
    stop = False
    while not stop:
        try:
            message = rsa.decrypt(client.recv(1024), privet_key).decode()
            self.update_chat_text(message)
        except Exception as ex:
            print("ERROR:", ex)
            client.close()
            stop = True

class NeuralWebChat(App):
def build(self):
return MyRoot()

neuralWebChat = NeuralWebChat()
neuralWebChat.run()
some of my error during converting code using buildozer (note that despite these error i get an .apk app)

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/lib2to3/tests/data/false_encoding.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/lib2to3/tests/data/false_encoding.py", line 2
print '#coding=0'
^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/lib2to3/tests/data/py2_test_grammar.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/lib2to3/tests/data/py2_test_grammar.py", line 31
self.assertEquals(0377, 255)
^
SyntaxError: unknown encoding: uft-8

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/bad_coding2.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/bad_coding2.py", line 0
SyntaxError: encoding problem: utf8 with BOM

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/bad_getattr.py'...
Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/bad_getattr2.py'...
Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/bad_getattr3.py'...
Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_3131.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_3131.py", line 2
€ = 2
^
SyntaxError: invalid character '€' (U+20AC)

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future10.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future10.py", line 3
from future import print_function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from future imports must occur at the beginning of the file

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future3.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future3.py", line 3
from future import rested_snopes
^
SyntaxError: future feature rested_snopes is not defined

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future4.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future4.py", line 3
from future import nested_scopes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from future imports must occur at the beginning of the file

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future5.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future5.py", line 4
from future import nested_scopes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from future imports must occur at the beginning of the file

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future6.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future6.py", line 3
from future import nested_scopes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from future imports must occur at the beginning of the file

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future7.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future7.py", line 3
from future import nested_scopes; import string; from future import
^
SyntaxError: from future imports must occur at the beginning of the file

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future8.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future8.py", line 3
from future import *
^
SyntaxError: future feature * is not defined

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future9.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_future9.py", line 3
from future import nested_scopes, braces
^
SyntaxError: not a chance

Compiling '/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_pep3120.py'...
*** File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/test/badsyntax_pep3120.py", line 1
print("b�se")
^
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xf6 in position 1: invalid start byte

@Alikhosravi22 Alikhosravi22 reopened this Jul 25, 2023
@Alikhosravi22 Alikhosravi22 changed the title kivy/lib/gstplayer/_gstplayer.pyx:418:34: Cannot assign type 'void (void *, int, int, char *, int) except * nogil' to 'appcallback_t' Exception in thread background thread for pid 321555: my python app doesn't work after converting it to an .apk file using buildozer Jul 25, 2023
@theseafaringturtle
Copy link

theseafaringturtle commented Jul 25, 2023

Edit: downgrading system cython to 0.29.x fixed the previous error for me.

Regarding your latest error:
It's just the tests for 2to3 that are not working, they are not required for the functioning of the app.
Does the app launch, ie do you see the kivy loading screen before it crashes, or is there a command line error before that while deploying?

@misl6
Copy link
Member

misl6 commented Jul 26, 2023

As per docs, Cython<3.0.0 is needed in order to use python-for-android and buildozer.
2to3 is not failing, these tests are supposed to fail 😀

@misl6 misl6 closed this as completed Jul 26, 2023
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

3 participants