Kivy / Python с Buildozer для Android APK - PullRequest
0 голосов
/ 02 апреля 2020

привет из Австрии!

В настоящее время я участвую в дипломной работе и пытаюсь получить файл Python / Kivy в Android APK. Я уже знаю, что бульдозер может это сделать.

Я уже слишком много часов пытался сделать это самостоятельно с помощью buildozer, но каждый раз, когда я устранял ошибку, сразу появлялось следующее сообщение об ошибке. Я попробовал это в терминальном приложении Ubuntu, Virtual Box с Linux, ... ничего не получалось.

Теперь я спрашиваю вас, ребята, можете ли вы сделать это для меня, пожалуйста:)

требования в .spe c файле:

  1. garden_requierements = джойстик
  2. INTE RNET в Android требования
  3. ориентация = портрет
  4. в полноэкранном режиме должно быть 1

Вот файл python (должен быть назван в main.py):

import threading
import time
import socket

from kivy.config import Config
from kivy.app import App
from kivy.garden.joystick import Joystick
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.properties import StringProperty
from kivy.core.window import Window

Window.clearcolor = (1,  1,  1,  1)

global connection_check_rpi
global connection_check_cam
global driving_assistant
global vel
global m
global cruise_control
global tempHelper

vel = "0.0"
tempHelper = 0

driving_assistant=False
cruise_control = False
connection_check_rpi=False
connection_check_cam=False

presentation = Builder.load_string(     #place all objects in GUI
"""
#File name: accept_SSCc.py
#: import Joystick kivy.garden.joystick.Joystick

<Interface>:
    Image:
        id: pic
        source:'c:/python/bg.png'
        pos: root.width/2+680, root.height/2+500
        size_hint: 0.4, 0.4
        allow_stretch: True
    Label:
        id: con1
        text: '[color=010203]'+root.connection1+'[/color]'
        pos: root.width/2-222, -root.height/2-84
        markup: True
    Label:
        id: con2
        text: '[color=010203]'+root.connection2+'[/color]'
        pos: root.width/2-252, -root.height/2-30
        markup: True
    Label:
        id: auto
        text: '[size=20][color='+root.colorauto+']'+root.auto_label+'[/color][/size]'
        pos: 0, -root.height/2+70
        markup: True
    Label:
        id: rpm
        text: '[size=40][color=0039FF]'+root.rpm+'[/color][/size]'
        pos: 0, -root.height/2+120
        markup: True
    Label:
        id: cc
        text: '[size=20][color='+root.colorcc+']'+root.cc_label+'[/color][/size]'
        pos: 0, -root.height/2+50
        markup: True
    Label:
        id: value
        text: '[size=20][color=000000]'+root.cc_value+'[/color][/size]'
        pos: root.width/2-170, -root.height/2+200
        markup: True
    Button:
        text: "ANBS"
        font_size: 40
        size_hint: None, None
        size: 175, 120
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2-320, 2*root.height/7-110
        on_press: root.button_auto()
    Button:
        text: "CC"
        font_size: 40
        size_hint: None, None
        size: 180, 60
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2+140, 2*root.height/7-50
        on_press: root.button_cc()
    Button:
        text: "+"
        font_size: 40
        size_hint: None, None
        size: 90, 60
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2+140, 2*root.height/7-110
        on_press: root.button_faster()
    Button:
        text: "-"
        font_size: 40
        size_hint: None, None
        size: 90, 60
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2+230, 2*root.height/7-110
        on_press: root.button_slower()
    Button:
        text: "sh"
        font_size: 40
        size_hint: None, None
        size: 200, 70
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2+120, 1.7*root.height/2-10
        on_press: root.button_sh()
    Button:
        text: "dc"
        font_size: 40
        size_hint: None, None
        size: 200, 70
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2-100, 1.7*root.height/2-10
        on_press: root.button_dc()
    Button:
        text: "con"
        font_size: 40
        size_hint: None, None
        size: 200, 70
        color: (1, 1, 1, 1)
        background_color:(0, 0, 0, 1)
        pos: root.width/2-320, 1.7*root.height/2-10
        on_press: root.button_con()
    Joystick:
        outer_size: 0.5
        inner_size: 0.25
        pad_size:   0.5
        outer_line_width: 0.01
        inner_line_width: 0.01
        pad_line_width:   0.01
        outer_background_color: (0.5, 0, 0, 1)
        outer_line_color:       (0, 0, 0, 1)
        inner_background_color: (0.2,  0,  0, 1)
        inner_line_color:       (0,  0,  0,  1)
        pad_background_color:   (0,  0,  0,  0.96)
        pad_line_color:         (1,  0,  0,  0.5)
        size_hint: 0.7, 0.7
        pos: root.width/4-145, root.height/5
""")

class Interface(FloatLayout):
    connection1=StringProperty()
    connection2=StringProperty()
    auto_label=StringProperty()
    cc_label = StringProperty()
    rpm = StringProperty()
    colorcc = StringProperty()
    colorauto = StringProperty()
    cc_value = StringProperty()
    def __init__(self, **kwargs):
        global vel
        super(Interface, self).__init__(**kwargs)
        self.connection1 = "              rpi: dc"
        self.connection2 = "               cam: dc"
        self.auto_label = "Notbremssystem off"
        self.cc_label = "CruiseControl off"
        self.stop_platzhalter = ""
        self.rpm = str(vel)+" km/h"
        self.colorauto = "FF0000"
        self.colorcc = "FF0000"
        self.cc_value = "Control: None"

    def button_cc(self, *args):
        global connection_check_rpi
        global connection_check_cam
        global command
        global cruise_control
        global s1
        global joystick_data
        global tempHelper

        if connection_check_rpi == True: #gehört noch auf true geändert
            if cruise_control == False:

                cruise_control = True
                command="cc_on"
                s1.send(str.encode(command))

                tempHelper = 7
                print(tempHelper)

                self.cc_label = "CruiseControl on"
                self.colorcc = "009910"
                self.cc_value = "Control: %i km/h" % tempHelper 

            elif cruise_control == True:

                cruise_control = False
                command="cc_off"
                s1.send(str.encode(command))

                tempHelper = 0
                print(tempHelper)

                self.cc_label = "CruiseControl off"
                self.colorcc = "FF0000"
                self.cc_value = "Control: None"

    def button_faster(self, *args):
        global connection_check_rpi
        global connection_check_cam
        global cruise_control
        global command
        global s1
        global joystick_data
        global tempHelper

        if connection_check_rpi == True and cruise_control == True: #auf True
            if tempHelper < 10.5:
                tempHelper += 1
                print(tempHelper)
                command="cc_faster"
                s1.send(str.encode(command))
                self.cc_value = "Control: %i km/h" % tempHelper 

    def button_slower(self, *args):
        global connection_check_rpi
        global connection_check_cam
        global cruise_control
        global command
        global s1
        global joystick_data
        global tempHelper

        if connection_check_rpi == True and cruise_control == True: #auf True
            if tempHelper > 0.5:
                tempHelper -= 1
                print(tempHelper)
                command="cc_slower"
                s1.send(str.encode(command))
                self.cc_value = "Control: %i km/h" % tempHelper 

    def button_sh(*args):               #shut servers down
        global connection_check_rpi
        global connection_check_cam
        global s1
        global s2
        command="sh"
        if connection_check_rpi == True:
            s1.send(str.encode(command))
            s1.close()
        if connection_check_cam == True:
            s2.send(str.encode(command))
            s2.close()
        Smart3DControl().stop()

    def button_dc(self, *args):         #disconnect from server
        global connection_check_rpi
        global connection_check_cam
        global s1
        global s2
        command="dc"
        if connection_check_rpi == True:
            s1.send(str.encode(command))
            s1.close()
            connection_check_rpi=False
        if connection_check_cam == True:
            s2.send(str.encode(command))
            s2.close()
            connection_check_cam=False
        self.connection1 = "              rpi: dc"
        self.connection2 = "               cam: dc"
        print("disconnected")

    def button_auto(self, *args):       #de/activate driving assistant
        global s1
        global s2
        print("auto")
        command="auto"
        if connection_check_rpi == True and connection_check_cam == True:
            s1.send(str.encode(command))
            s2.send(str.encode(command))
            global driving_assistant
            if driving_assistant == False:
                driving_assistant = True
                self.auto_label = "Fahrassistent on"
                self.colorauto = "009910"
            elif driving_assistant == True:
                self.auto_label = "Fahrassistent off"
                self.colorauto = "FF0000"
                driving_assistant = False

    def button_con(self, *args):        #connect to servers
        global connection_check_rpi
        global connection_check_cam
        global s1
        global s2
        print("con")

        host1 = '192.168.42.1'  # raspberry
        port1 = 5560

        host2 = '192.168.42.2'  # camera
        port2 = 5568
        try:

            if connection_check_rpi == False:
                s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s1.connect((host1, port1))
                print(str(s1))
                self.connection1=str("rpi: "+host1)

                print("connected to rpi")
                connection_check_rpi=True
                print(s1)
                thread = Velocity()
                thread.start()
                thread1 = Ausgabe()
                thread1.start()

            if connection_check_cam == False:
                s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s2.connect((host2, port2))
                self.connection2=str("cam: "+host2)

                print("connected to camera")
                connection_check_cam=True
                print(s2)
        except:
            pass

    def update_label(self, *args):
        global vel
        global cruise_control
        global s1
        global m

        if str(vel)[1:2] is ".":
            vel = ' '+str(vel)[:3]
        else:
            vel = str(vel)[:4]

        self.rpm = str(vel)+" km/h"

    def update_states(self, *args):
        global vel
        global cruise_control
        global s1
        global m

        self.cc_label = "CruiseControl off"
        self.colorcc = "FF0000"
        self.cc_value = "Control: None"

        if cruise_control == True:
            command="cc_off"
            s1.send(str.encode(command))
        cruise_control = False

class Smart3DControl(App):
    global vel
    global m
    def build(self):
        global m
        self.root = Interface()
        joysticks = self.get_joystick(self.root)   #assign joystick to variable

        for joystick in joysticks:
            joystick.bind(pad=self._update_joystick_output) #bind function to joystick

        from functools import partial
        from kivy.clock import ClockBase

        Clock.schedule_interval(partial(self.root.update_label), .05)

    def get_joystick(self, parent):
        joysticks = []
        if isinstance(parent, Joystick):
            joysticks.append(parent)
        elif hasattr(parent, 'children'):
            for child in parent.children:
                joysticks.extend(self.get_joystick(child))
        return joysticks

    def _update_joystick_output(self, instance, pad):   #send joystick data
        global driving_assistant
        global connection_check_rpi
        global joystick_data
        global m
        m = str(instance.magnitude)[0:5]
        a = str(instance.angle)[0:5]
        joystick_data=m+" "+a
        #print(joystick_data)
        self.root.update_states()
        if connection_check_rpi == True:
            if(len(joystick_data) <= 12):
                s1.send(str.encode(joystick_data))

class Velocity(threading.Thread): #get velocity from raspberry
    def run(self):
        global vel
        global s1
        global connection_check_rpi

        while True:
            if connection_check_rpi == True:
                try:
                    rpm_data = s1.recv(1024)
                    vel = rpm_data.decode('utf-8')
                except:
                    break
            else:
                break

Smart3DControl().run()

Программа работает без проблем

Надеюсь, кто-нибудь может мне помочь:)

Если вам нужна какая-либо информация, опубликуйте ее в комментариях. Я помогу вам столько, сколько смогу.

...