Я студент бакалавра инженерных наук и все еще учусь на втором курсе, но пытаюсь разработать базовое приложение-помощник, используя Python и Kivy (которое я пытался изучить самостоятельно).У меня есть код, написанный для приложения, который отлично работает в моей системе Windows, но для упаковки исходного кода в APK я использовал учетную запись Google Collab и установил среду Ubuntu и buildozer. APK также создается успешно, но при установке на любое устройство Android приложение вылетает сразу после отображения «(Kivy Logo)Loading...»
Я пробовал менять части кода, а также содержимое файла спецификации, но ничего не помогло.
Я новичок в Kivy и разработке приложений, поэтому (честно говоря) мало что знаю о logcat и отладке apk.
Я бы буду очень благодарен, если кто-нибудь сможет мне с этим помочь.
Это мой код:
from kivy.app import App
from kivy.config import Config
Config.set('graphics','resizable',True)
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.pagelayout import PageLayout
from kivy.uix.gridlayout import GridLayout
import datetime
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
import os
from kivy.clock import Clock
from kivy.core.window import Window
OldNameOfFile=""
OldText=""
firsttime=1
pcheck=0
FileListString=""
class MyLayout(FloatLayout):
def ButtonMaker(self):
self.Timeb=Button(
text="Time",size_hint=(.3,.3),pos_hint={"x":.09,"y":.6})
self.WriteB=Button(
text="Press here to \nwrite a note",size_hint=(.3,.3),pos_hint={"x":.6,"y":.6})
self.NoteB=Button(
text="Press here to view\n a written note",size_hint=(.3,.3),pos_hint={"x":.09,"y":.2})
self.SWB=Button(
text="Press here for \nStop-Watch",size_hint=(.3,.3),pos_hint={"x":.6,"y":.2})
self.STOPWATCHStartB=Button(
text="Start",size_hint=(.25,.20),pos_hint={"x":.04,"y":.3})
self.STOPWATCHStopB=Button(
text="Stop",size_hint=(.25,.20),pos_hint={"x":.36,"y":.3})
self.STOPWATCHCloseB=Button(
text="Close",size_hint=(.25,.20),pos_hint={"x":.68,"y":.3})
self.STOPWATCHPauseB=Button(
text="Pause",size_hint=(.25,.20),pos_hint={"x":.2,"y":.05})
self.STOPWATCHResetB=Button(
text="Reset",size_hint=(.25,.20),pos_hint={"x":.53,"y":.05})
self.STOPWATCHDisp=TextInput(
text=" 00:00:00:00",size_hint=(.9,.3),font_size='125sp',readonly=True,pos_hint={"x":.05,"y":.6})
self.TimeBTime=Button(
text="The time is :",background_color="black",font_size=40,pos_hint={"x":0,"y":.3})
self.TimeBCloseB=Button(
text="Click to close",size_hint=(.2,.2),pos_hint={"x":.35,"y":.2})
self.WriteBNameB=Button(
text="Enter name of file here : (or Enter name of already existing file to edit before entering text)",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.9})
self.WriteBTIB=Button(
text="Enter text here :",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.78})
self.WriteBSubmitB=Button(
text="Save",size_hint=(.4,.1),pos_hint={"x":0.07,"y":.1})
self.WriteBCloseB=Button(
text="Close",size_hint=(.4,.1),pos_hint={"x":.53,"y":.1})
self.WriteBTI=TextInput(
font_size=30,size_hint=(.95,.55),pos_hint={"x":0.02,"y":.25},multiline=True)
self.WriteBName=TextInput(
font_size=20,size_hint=(.95,.07),pos_hint={"x":0.02,"y":.85})
self.WriteBp=Button(
text="Empty name error...",background_color="black",size_hint=(.4,.08),pos_hint={"x":0.3,"y":0.01})
self.NoteBName=TextInput(
text="Select a file name from below files",font_size=20,size_hint=(.95,.07),pos_hint={"x":.02,"y":.85})
self.NoteBNameB=Button(
text="Enter name of file here :",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.9})
self.NoteBTextData=TextInput(
font_size=20,size_hint=(.95,.55),pos_hint={"x":0.02,"y":.25},readonly=True,multiline=True)
self.NoteBTextDataB=Button(
text="Data of files :",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.78})
self.NoteBSubmitB=Button(
text="Submit",size_hint=(.4,.1),pos_hint={"x":0.07,"y":.13})
self.NoteBCloseB=Button(
text="Close",size_hint=(.4,.1),pos_hint={"x":0.53,"y":.13})
self.NoteBDeleteB=Button(
text="Delete this",size_hint=(.38,.09),pos_hint={"x":0.3,"y":0.02})
self.NoteBp=Button(
text="Empty name error...",background_color="black",size_hint=(.4,.1),pos_hint={"x":0.3,"y":0.02})
self.HomePage1List=[
self.Timeb,self.WriteB,self.NoteB,self.SWB]
self.STOPWATCHList=[
self.STOPWATCHStartB,self.STOPWATCHStopB,self.STOPWATCHCloseB,self.STOPWATCHPauseB,self.STOPWATCHResetB,self.STOPWATCHDisp]
self.TimeBList=[
self.TimeBTime,self.TimeBCloseB]
self.WriteBList=[
self.WriteBNameB,self.WriteBTIB,self.WriteBName,self.WriteBTI,self.WriteBSubmitB,self.WriteBCloseB]
self.NoteBList=[
self.NoteBNameB,self.NoteBName,self.NoteBTextDataB,self.NoteBTextData,self.NoteBSubmitB,self.NoteBCloseB,self.NoteBDeleteB]
def BindButtons(self):
self.SWB.bind(on_press=self.StopWatchPress)
self.Timeb.bind(on_press=self.TimeBPress)
self.WriteB.bind(on_press=self.WriteBPress)
self.NoteB.bind(on_press=self.NoteBPress)
self.STOPWATCHStartB.bind(on_press=self.OnStart)
self.STOPWATCHStopB.bind(on_press=self.OnStop)
self.STOPWATCHResetB.bind(on_press=self.OnReset)
self.STOPWATCHPauseB.bind(on_press=self.OnPause)
self.STOPWATCHCloseB.bind(on_press=self.StopWatchClose)
self.TimeBCloseB.bind(on_press=self.TimeBClose)
self.WriteBCloseB.bind(on_press=self.WriteBClose)
self.WriteBSubmitB.bind(on_press=self.Saveandwrite)
self.NoteBSubmitB.bind(on_press=self.OpenFile)
self.NoteBCloseB.bind(on_press=self.NoteBClose)
self.NoteBDeleteB.bind(on_press=self.NoteBDelete)
def AddHomePage1(self):
for b in self.HomePage1List:
self.add_widget(b)
def RemHomePage1(self):
for b in self.HomePage1List:
self.remove_widget(b)
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.ButtonMaker()
self.BindButtons()
self.AddHomePage1()
def StopWatchPress(self,button):
self.RemHomePage1()
self.STOPWATCHpause=0
self.STOPWATCHstop=0
Clock.unschedule(self.increment_STOPWATCHtime)
self.STOPWATCHtime=["00","00","00","0"]
self.STOPWATCHDisp.text=" 00:00:00:00"
for b in self.STOPWATCHList:
self.add_widget(b)
def TimeBPress(self,button):
self.RemHomePage1()
time=datetime.datetime.now()
time=time.strftime("%H:%M:%S")
self.TimeBTime.text=self.TimeBTime.text[:13]+str(time)
for b in self.TimeBList:
self.add_widget(b)
def WriteBPress(self,button):
self.RemHomePage1()
global firsttime
firsttime=1
for b in self.WriteBList:
self.add_widget(b)
def NoteBPress(self,button):
self.RemHomePage1()
path=os.getcwd()
FileList=os.listdir(path)
global FileListString
FileListString="Names of all files are : \n"
for k in FileList:
if k[-4:]==".txt":
FileListString=FileListString+k+"\n"
self.NoteBTextData.text=FileListString
for b in self.NoteBList:
self.add_widget(b)
def StopWatchClose(self,button):
for b in self.STOPWATCHList:
self.remove_widget(b)
self.AddHomePage1()
def TimeBClose(self,button):
self.remove_widget(self.TimeBCloseB)
self.remove_widget(self.TimeBTime)
self.AddHomePage1()
def Saveandwrite(self,button):
global OldNameOfFile
global OldText
global firsttime
if firsttime==1 or (OldNameOfFile!=self.WriteBName.text.strip() or OldText!=self.WriteBTI.text):
file="new"
NameOfFile=self.WriteBName.text.strip()
else:
file="old"
if file=="old":
return
global pcheck
OldNameOfFile=NameOfFile
if NameOfFile=="":
if pcheck==0:
self.add_widget(self.WriteBp)
pcheck=1
return
if NameOfFile!="":
self.remove_widget(self.WriteBp)
pcheck=0
if NameOfFile[-4:]==".txt":
NameOfFile=NameOfFile[:-4]
try:
NewF=open(NameOfFile+".txt","r")
if self.WriteBTI.text=="":
self.WriteBTI.text=NewF.read()
NewF.close()
except:
pass
NewF=open(NameOfFile+".txt","w")
self.WriteBName.text=NameOfFile
Text=self.WriteBTI.text
OldText=Text
NewF.write(Text)
NewF.close()
firsttime=0
return
def WriteBClose(self,button):
for b in self.WriteBList:
self.remove_widget(b)
global pcheck
global OldNameOfFile
global firsttime
firsttime=1
OldNameOfFile=""
self.WriteBName.text=""
self.WriteBTI.text=""
if pcheck==1:
pcheck=0
self.remove_widget(self.WriteBp)
self.AddHomePage1()
def OpenFile(self,button):
global FileListString
NameOfFile=self.NoteBName.text.strip()
global pcheck
if NameOfFile=="":
if pcheck==0:
self.add_widget(self.NoteBp)
pcheck=1
return
if NameOfFile!="":
self.remove_widget(self.NoteBp)
pcheck=0
try:
if NameOfFile[-4:]==".txt":
NameOfFile=NameOfFile[:-4]
NewF=open(NameOfFile+".txt","r")
self.NoteBTextData.text=NewF.read()
except FileNotFoundError:
self.NoteBTextData.text=FileListString
self.NoteBName.text="No Such File.. Select a name from below files.."
def NoteBDelete(self,button):
NameOfFile=self.NoteBName.text.strip()
if NameOfFile[-4:]==".txt":
NameOfFile=NameOfFile[:-4]
try:
os.remove(NameOfFile+".txt")
except:
pass
path=os.getcwd()
FileList=os.listdir(path)
global FileListString
FileListString="Names of all files are : \n"
for k in FileList:
if k[-4:]==".txt":
FileListString=FileListString+k+"\n"
self.NoteBTextData.text=FileListString
self.NoteBName.text="Select a file name from below files"
def NoteBClose(self,button):
for b in self.NoteBList:
self.remove_widget(b)
global pcheck
global FileListString
FileListString=""
self.NoteBName.text="Select a file name from below files"
if pcheck==1:
pcheck=0
self.remove_widget(self.NoteBp)
self.AddHomePage1()
def increment_STOPWATCHtime(self,interval):
if int(self.STOPWATCHtime[3])90:
self.STOPWATCHtime[2]=str(int(self.STOPWATCHtime[2])+1)
self.STOPWATCHtime[3]="00"
if self.STOPWATCHtime[2]=="60":
self.STOPWATCHtime[1]=str(int(self.STOPWATCHtime[1])+1)
self.STOPWATCHtime[2]="00"
self.STOPWATCHtime[3]="30"
if self.STOPWATCHtime[1]=="60":
self.STOPWATCHtime[0]=str(int(self.STOPWATCHtime[0])+1)
self.STOPWATCHtime[1]="00"
if self.STOPWATCHtime[0]=="24":
self.STOPWATCHtime=["00","00","00","00"]
for k in range(4):
if int(self.STOPWATCHtime[k])
Подробнее здесь: [url]https://stackoverflow.com/questions/67420082/kivy-application-crash-after-loading[/url]
Я студент бакалавра инженерных наук и все еще учусь на втором курсе, но пытаюсь разработать базовое приложение-помощник, используя Python и Kivy (которое я пытался изучить самостоятельно).У меня есть код, написанный для приложения, который отлично работает в моей системе Windows, но для упаковки исходного кода в APK я использовал учетную запись Google Collab и установил среду Ubuntu и buildozer. APK также создается успешно, но при установке на любое устройство Android приложение вылетает сразу после отображения «(Kivy Logo)Loading...» Я пробовал менять части кода, а также содержимое файла спецификации, но ничего не помогло. Я новичок в Kivy и разработке приложений, поэтому (честно говоря) мало что знаю о logcat и отладке apk. Я бы буду очень благодарен, если кто-нибудь сможет мне с этим помочь. Это мой код: [code] from kivy.app import App from kivy.config import Config Config.set('graphics','resizable',True) from kivy.uix.button import Button from kivy.uix.floatlayout import FloatLayout from kivy.uix.pagelayout import PageLayout from kivy.uix.gridlayout import GridLayout import datetime from kivy.uix.popup import Popup from kivy.uix.label import Label from kivy.uix.textinput import TextInput import os from kivy.clock import Clock from kivy.core.window import Window
class MyLayout(FloatLayout): def ButtonMaker(self): self.Timeb=Button( text="Time",size_hint=(.3,.3),pos_hint={"x":.09,"y":.6}) self.WriteB=Button( text="Press here to \nwrite a note",size_hint=(.3,.3),pos_hint={"x":.6,"y":.6}) self.NoteB=Button( text="Press here to view\n a written note",size_hint=(.3,.3),pos_hint={"x":.09,"y":.2}) self.SWB=Button( text="Press here for \nStop-Watch",size_hint=(.3,.3),pos_hint={"x":.6,"y":.2}) self.STOPWATCHStartB=Button( text="Start",size_hint=(.25,.20),pos_hint={"x":.04,"y":.3}) self.STOPWATCHStopB=Button( text="Stop",size_hint=(.25,.20),pos_hint={"x":.36,"y":.3}) self.STOPWATCHCloseB=Button( text="Close",size_hint=(.25,.20),pos_hint={"x":.68,"y":.3}) self.STOPWATCHPauseB=Button( text="Pause",size_hint=(.25,.20),pos_hint={"x":.2,"y":.05}) self.STOPWATCHResetB=Button( text="Reset",size_hint=(.25,.20),pos_hint={"x":.53,"y":.05}) self.STOPWATCHDisp=TextInput( text=" 00:00:00:00",size_hint=(.9,.3),font_size='125sp',readonly=True,pos_hint={"x":.05,"y":.6}) self.TimeBTime=Button( text="The time is :",background_color="black",font_size=40,pos_hint={"x":0,"y":.3}) self.TimeBCloseB=Button( text="Click to close",size_hint=(.2,.2),pos_hint={"x":.35,"y":.2}) self.WriteBNameB=Button( text="Enter name of file here : (or Enter name of already existing file to edit before entering text)",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.9}) self.WriteBTIB=Button( text="Enter text here :",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.78}) self.WriteBSubmitB=Button( text="Save",size_hint=(.4,.1),pos_hint={"x":0.07,"y":.1}) self.WriteBCloseB=Button( text="Close",size_hint=(.4,.1),pos_hint={"x":.53,"y":.1}) self.WriteBTI=TextInput( font_size=30,size_hint=(.95,.55),pos_hint={"x":0.02,"y":.25},multiline=True) self.WriteBName=TextInput( font_size=20,size_hint=(.95,.07),pos_hint={"x":0.02,"y":.85}) self.WriteBp=Button( text="Empty name error...",background_color="black",size_hint=(.4,.08),pos_hint={"x":0.3,"y":0.01}) self.NoteBName=TextInput( text="Select a file name from below files",font_size=20,size_hint=(.95,.07),pos_hint={"x":.02,"y":.85}) self.NoteBNameB=Button( text="Enter name of file here :",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.9}) self.NoteBTextData=TextInput( font_size=20,size_hint=(.95,.55),pos_hint={"x":0.02,"y":.25},readonly=True,multiline=True) self.NoteBTextDataB=Button( text="Data of files :",size_hint=(1,.09),background_color="black",pos_hint={"x":0.01,"y":.78}) self.NoteBSubmitB=Button( text="Submit",size_hint=(.4,.1),pos_hint={"x":0.07,"y":.13}) self.NoteBCloseB=Button( text="Close",size_hint=(.4,.1),pos_hint={"x":0.53,"y":.13}) self.NoteBDeleteB=Button( text="Delete this",size_hint=(.38,.09),pos_hint={"x":0.3,"y":0.02}) self.NoteBp=Button( text="Empty name error...",background_color="black",size_hint=(.4,.1),pos_hint={"x":0.3,"y":0.02})
self.HomePage1List=[ self.Timeb,self.WriteB,self.NoteB,self.SWB] self.STOPWATCHList=[ self.STOPWATCHStartB,self.STOPWATCHStopB,self.STOPWATCHCloseB,self.STOPWATCHPauseB,self.STOPWATCHResetB,self.STOPWATCHDisp] self.TimeBList=[ self.TimeBTime,self.TimeBCloseB] self.WriteBList=[ self.WriteBNameB,self.WriteBTIB,self.WriteBName,self.WriteBTI,self.WriteBSubmitB,self.WriteBCloseB] self.NoteBList=[ self.NoteBNameB,self.NoteBName,self.NoteBTextDataB,self.NoteBTextData,self.NoteBSubmitB,self.NoteBCloseB,self.NoteBDeleteB] def BindButtons(self): self.SWB.bind(on_press=self.StopWatchPress) self.Timeb.bind(on_press=self.TimeBPress) self.WriteB.bind(on_press=self.WriteBPress) self.NoteB.bind(on_press=self.NoteBPress) self.STOPWATCHStartB.bind(on_press=self.OnStart) self.STOPWATCHStopB.bind(on_press=self.OnStop) self.STOPWATCHResetB.bind(on_press=self.OnReset) self.STOPWATCHPauseB.bind(on_press=self.OnPause) self.STOPWATCHCloseB.bind(on_press=self.StopWatchClose) self.TimeBCloseB.bind(on_press=self.TimeBClose) self.WriteBCloseB.bind(on_press=self.WriteBClose) self.WriteBSubmitB.bind(on_press=self.Saveandwrite) self.NoteBSubmitB.bind(on_press=self.OpenFile) self.NoteBCloseB.bind(on_press=self.NoteBClose) self.NoteBDeleteB.bind(on_press=self.NoteBDelete) def AddHomePage1(self): for b in self.HomePage1List: self.add_widget(b) def RemHomePage1(self): for b in self.HomePage1List: self.remove_widget(b)
def StopWatchPress(self,button): self.RemHomePage1() self.STOPWATCHpause=0 self.STOPWATCHstop=0 Clock.unschedule(self.increment_STOPWATCHtime) self.STOPWATCHtime=["00","00","00","0"] self.STOPWATCHDisp.text=" 00:00:00:00" for b in self.STOPWATCHList: self.add_widget(b) def TimeBPress(self,button): self.RemHomePage1() time=datetime.datetime.now() time=time.strftime("%H:%M:%S") self.TimeBTime.text=self.TimeBTime.text[:13]+str(time) for b in self.TimeBList: self.add_widget(b) def WriteBPress(self,button): self.RemHomePage1() global firsttime firsttime=1 for b in self.WriteBList: self.add_widget(b) def NoteBPress(self,button): self.RemHomePage1() path=os.getcwd() FileList=os.listdir(path) global FileListString FileListString="Names of all files are : \n" for k in FileList: if k[-4:]==".txt": FileListString=FileListString+k+"\n" self.NoteBTextData.text=FileListString for b in self.NoteBList: self.add_widget(b)
def StopWatchClose(self,button): for b in self.STOPWATCHList: self.remove_widget(b) self.AddHomePage1() def TimeBClose(self,button): self.remove_widget(self.TimeBCloseB) self.remove_widget(self.TimeBTime) self.AddHomePage1() def Saveandwrite(self,button): global OldNameOfFile global OldText global firsttime if firsttime==1 or (OldNameOfFile!=self.WriteBName.text.strip() or OldText!=self.WriteBTI.text): file="new" NameOfFile=self.WriteBName.text.strip() else: file="old" if file=="old": return global pcheck OldNameOfFile=NameOfFile if NameOfFile=="": if pcheck==0: self.add_widget(self.WriteBp) pcheck=1 return if NameOfFile!="": self.remove_widget(self.WriteBp) pcheck=0 if NameOfFile[-4:]==".txt": NameOfFile=NameOfFile[:-4] try: NewF=open(NameOfFile+".txt","r") if self.WriteBTI.text=="": self.WriteBTI.text=NewF.read() NewF.close() except: pass NewF=open(NameOfFile+".txt","w") self.WriteBName.text=NameOfFile Text=self.WriteBTI.text OldText=Text NewF.write(Text) NewF.close() firsttime=0 return def WriteBClose(self,button): for b in self.WriteBList: self.remove_widget(b) global pcheck global OldNameOfFile global firsttime firsttime=1 OldNameOfFile="" self.WriteBName.text="" self.WriteBTI.text="" if pcheck==1: pcheck=0 self.remove_widget(self.WriteBp) self.AddHomePage1() def OpenFile(self,button): global FileListString NameOfFile=self.NoteBName.text.strip() global pcheck if NameOfFile=="": if pcheck==0: self.add_widget(self.NoteBp) pcheck=1 return if NameOfFile!="": self.remove_widget(self.NoteBp) pcheck=0 try: if NameOfFile[-4:]==".txt": NameOfFile=NameOfFile[:-4] NewF=open(NameOfFile+".txt","r") self.NoteBTextData.text=NewF.read() except FileNotFoundError: self.NoteBTextData.text=FileListString self.NoteBName.text="No Such File.. Select a name from below files.." def NoteBDelete(self,button): NameOfFile=self.NoteBName.text.strip() if NameOfFile[-4:]==".txt": NameOfFile=NameOfFile[:-4] try: os.remove(NameOfFile+".txt") except: pass path=os.getcwd() FileList=os.listdir(path) global FileListString FileListString="Names of all files are : \n" for k in FileList: if k[-4:]==".txt": FileListString=FileListString+k+"\n" self.NoteBTextData.text=FileListString self.NoteBName.text="Select a file name from below files" def NoteBClose(self,button): for b in self.NoteBList: self.remove_widget(b) global pcheck global FileListString FileListString="" self.NoteBName.text="Select a file name from below files" if pcheck==1: pcheck=0 self.remove_widget(self.NoteBp) self.AddHomePage1() def increment_STOPWATCHtime(self,interval): if int(self.STOPWATCHtime[3])90: self.STOPWATCHtime[2]=str(int(self.STOPWATCHtime[2])+1) self.STOPWATCHtime[3]="00" if self.STOPWATCHtime[2]=="60": self.STOPWATCHtime[1]=str(int(self.STOPWATCHtime[1])+1) self.STOPWATCHtime[2]="00" self.STOPWATCHtime[3]="30" if self.STOPWATCHtime[1]=="60": self.STOPWATCHtime[0]=str(int(self.STOPWATCHtime[0])+1) self.STOPWATCHtime[1]="00" if self.STOPWATCHtime[0]=="24": self.STOPWATCHtime=["00","00","00","00"] for k in range(4): if int(self.STOPWATCHtime[k])