问题描述
我是kivy库编程的初学者,但我已经完成了非常简单的应用程序,例如Kivy教程.在桌面上,它很酷.但是比我想做的.apk文件(还没有使用过Linux).我已经尝试了很多步骤来制作.apk文件,但是最后,当我安装并打开该程序时.它有一个错误.我已经尝试了很多规格和new_android,但没有任何效果.最终,我将buildozer更新到了最新版本.但是现在,在buildozer android调试之后,他写了这个错误:
I'm beginner in kivy library programming, but I have done very simple application, like in Kivy tutorial. On desktop it works cool. But than I wanted to do .apk file(Hadn't used Linux). I've tried a lot of steps to do an .apk file, but finally when I've installed and opened this program. It had an error. I've tried a lot of specs and new_android, but nothing worked. Finally I've updated my buildozer to the last version. But now, after buildozer android debug, he writes this error:
IOError:[错误2]没有此类文件或目录:u'/home/kivy/reyyy/.buildozer/android/platform/build/dists/RetroApp/build/outputs/apk/RetroApp-debug.apk'.
IOError: [Errno 2] No such file or directory: u'/home/kivy/reyyy/.buildozer/android/platform/build/dists/RetroApp/build/outputs/apk/RetroApp-debug.apk'.
************* buildozer.spec ***************
*************buildozer.spec***************
[app]
title = Retro App
package.name = retroapp
package.domain = org.test
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
version = 1.0
requirements = kivy
orientation = landscape
osx.python_version = 3
osx.kivy_version = 1.9.1
fullscreen = 1
android.arch = armeabi-v7a
[buildozer]
log_level = 2
warn_on_root = 1
****** python3:main.py *******
******python3: main.py*******
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty,ObjectProperty,ReferenceListProperty,StringProperty
from kivy.vector import Vector
from kivy.clock import Clock
from kivy.uix.button import Button
from random import randint,choice
class RetryButton(Button):
pass
class PongBall(Widget):
velocity_y = NumericProperty(0)
velocity_x = NumericProperty(0)
velocity = ReferenceListProperty(velocity_x,velocity_y)
def move(self):
self.pos = Vector(*self.velocity)+self.pos
class PongPaddle(Widget):
score = NumericProperty(0)
def bounce_ball(self,ball):
if self.collide_widget(ball):
vx,vy = ball.velocity
offset = (ball.center_y - self.center_y) / (self.height /10.0)
bounced = Vector(-1 * vx, vy)
vel = bounced * 1.1
ball.velocity = vel.x, vel.y + offset
class PongGame(Widget):
ball = ObjectProperty(None)
player1 = ObjectProperty(None)
player2 = ObjectProperty(None)
win = NumericProperty(0)
middle_rectangle_opacity = NumericProperty(1)
winner = StringProperty('')
def __init__(self,**q):
super().__init__(**q)
self.btn = RetryButton(width = self.width)
self.btn.count = 0
self.max_score = 10
def serve_ball(self,vel = (10,0)):
self.ball.center = self.center
self.ball.velocity = Vector(*vel).rotate(choice([randint(0,30),randint(330,360)]))
def update(self,dt):
if self.win == 0:
self.ball.move()
self.player1.bounce_ball(self.ball)
self.player2.bounce_ball(self.ball)
if self.player1.score >= self.max_score or self.player2.score >=self.max_score:
if self.player1.score >= self.max_score:
self.winner = '1'
else:
self.winner = '2'
self.win = 1
self.middle_rectangle_opacity = 0
if (self.ball.y < self.y) or (self.ball.top > self.height):
self.ball.velocity_y *= -1
if self.ball.x<self.x:
self.player2.score += 1
self.serve_ball((10,0))
if self.ball.x > self.width - self.ball.width:
self.player1.score += 1
self.serve_ball((-10,0))
else:
if self.btn.count == 0:
self.btn.bind(on_press=self.retry)
self.add_widget(self.btn)
self.btn.count += 1
def on_touch_move(self, touch):
if touch.x < self.width/3.0:
self.player1.center_y = touch.y
if touch.x > self.width - self.width/3.0:
self.player2.center_y = touch.y
def retry(self,*q):
self.player1.score = 0
self.player2.score = 0
self.win = 0
self.middle_rectangle_opacity = 1
self.serve_ball()
self.remove_widget(self.btn)
self.btn.count = 0
class PongApp(App):
def build(self):
game = PongGame()
game.serve_ball()
Clock.schedule_interval(game.update, 1/30.0)
return game
if __name__ == '__main__':
PongApp().run()`
******** KV pong.kv *********
********KV pong.kv*********
#:kivy 1.0.9
<RetryButton>:
text: 'Retry'
font_size: 17
size: self.width, '100dp'
<PongBall>:
size:50,50
canvas.before:
Ellipse:
pos: self.pos
size: self.size
<PongPaddle>:
size: '25dp','200dp'
canvas:
Rectangle:
pos:self.pos
size: self.size
<PongGame>:
ball: pong_ball
player1: player_left
player2: player_right
canvas:
Color:
rgba: 1,1,1,root.middle_rectangle_opacity
Rectangle:
pos:self.center_x - 5,0
size: 10, self.height
Label:
font_size:35
center_x: root.center_x
center_y: root.height/4*3
text: "Player {} wins!!".format(root.winner)
color: 1,1,1,root.win
Label:
font_size: 70
center_x: root.width/4
top: root.top - 50
text: str(root.player1.score)
Label:
font_size: 70
center_x: root.width/4*3
top: root.top - 50
text: str(root.player2.score)
PongBall:
id: pong_ball
center: self.parent.center
PongPaddle:
id: player_left
x: root.x
center_y: root.center_y
PongPaddle:
id: player_right
x: root.width - self.width
center_y: root.center_y
请帮帮我!瓦迪姆.
推荐答案
请按如下所示更改您的Python脚本:
Please change your Python script as follow:
class PongGame(Widget):
...
def __init__(self, **kwargs):
super(PongGame, self).__init__(**kwargs)
...
def retry(self):
由于您使用的是Python 3.x,因此需要执行以下操作:
Since you are using Python 3.x, you need to do the following:
-
安装具有python3支持的Buildozer
Install Buildozer with python3 support
git clone https://github.com/kivy/buildozer
git clone https://github.com/kivy/buildozer
cd buildozer
cd buildozer
python setup.py构建
python setup.py build
sudo pip install -e.
sudo pip install -e .
在某处下载Crystax NDK并将其解压缩(〜/opt/是一种选择): https ://www.crystax.net/en/download
Download and extract the Crystax NDK somewhere (~/opt/ is one option): https://www.crystax.net/en/download
buildozer.spec
需求= python3crystax,奇异果
buildozer.spec
requirements = python3crystax,kivy
android.ndk = 10.3.2
android.ndk = 10.3.2
android.ndk_path =/opt/crystax-ndk-10.3.2
android.ndk_path = /opt/crystax-ndk-10.3.2
这篇关于IOError:[Errno 2]没有这样的文件或目录:u'/........./RetroApp-debug.apk'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!