Oct-03-2023, 07:11 PM
Hi, I have simple code for Flask local server:
I tried start main.py on Ubuntu, Windows, Anodroid mobile with Pydroid and it works well.
If I compile to apk and install on mobile phone, I see just loading and then app closes itself.
After Buildozer init I changed requirements to python3,flask,kivy,cython and Permissions=INTERNET.
I tried lot of configurations but always the same result = app closes itself.
If I used only gui in kivy, it works well. Other apps also works well - all without Flask.
Any idea how to do it?
Thanks.
import sys import io sys.stdout = io.StringIO() sys.stderr = io.StringIO() from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button from kivy.uix.label import Label from threading import Thread from flask import Flask # Flask server definition app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, Flask Server!' def run_flask_app(): app.run(host='0.0.0.0', port=8000, threaded=True) class ServerApp(App): def build(self): self.server_state_label = Label(text="Server is not running") self.start_server_button = Button(text="Start Server") self.start_server_button.bind(on_press=self.start_server) layout = BoxLayout(orientation="vertical") layout.add_widget(self.server_state_label) layout.add_widget(self.start_server_button) return layout def start_server(self, instance): try: # Start the Flask server in a thread server_thread = Thread(target=run_flask_app) server_thread.start() self.server_state_label.text = "Server is running" except Exception as e: self.server_state_label.text = "Error starting the server" if __name__ == '__main__': ServerApp().run()I want to compile it to apk for anodrid. I have Win11, installed Oracle VirtualBox with Ubuntu. I installed Kivy, Cython, Buildozer, Flask, etc.
I tried start main.py on Ubuntu, Windows, Anodroid mobile with Pydroid and it works well.
If I compile to apk and install on mobile phone, I see just loading and then app closes itself.
After Buildozer init I changed requirements to python3,flask,kivy,cython and Permissions=INTERNET.
I tried lot of configurations but always the same result = app closes itself.
If I used only gui in kivy, it works well. Other apps also works well - all without Flask.
Any idea how to do it?
Thanks.