android - 使用 buildozer kivy 的 800mb apk 文件

标签 android python python-3.x kivy buildozer

我是新的安卓开发者。我正在使用 python3.6 和 kivy 库来开发我的程序。我正在使用 Crystax NDK,一切都很好,除了一件事,应用程序太大 (800mb)。

如何让它们变小?

Python代码

    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(PongGame,self).__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:
                self.player1.center_y = touch.y
            if touch.x > self.width - self.width/3:
                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/60)
            return game

    if __name__ == '__main__':
       PongApp().run()

pong.kv文件

#:kivy 1.0.9
<RetryButton@Button>:
    text: 'Retry'
    font_size: 17
    size: self.width, '100dp'
<PongBall>:
    size: '50sp','50sp'
    canvas.before:
        Ellipse:
            pos: self.pos
            size: self.size

<PongPaddle>:
    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:
        size: root.width/30,root.height/3
        id: player_left
        x: root.x
        center_y: root.center_y
    PongPaddle:
        size: root.width/30,root.height/3
        id: player_right
        x: root.width - self.width
        center_y: root.center_y

buildozer.spec

title = RetroPong
package.name = retropong
package.domain = www.thelatish.lv
source.dir = .
source.include_exts = py,kv
version = 0.2
requirements =python3crystax,kivy
orientation = landscape
osx.python_version = 3
osx.kivy_version = 1.9.1
fullscreen = 1
android.ndk = 10.3.2
android.ndk_path = opt/crystax-ndk-10.3.2
android.arch =armeabi-v7a
log_level = 2
warn_on_root = 1

而且我认为我的文件树可以帮助您解决这个问题。

computer/home/ubuntu/qwerty:
  bin:
  buildozer:
  opt:
     crystax-ndk-10.3.2
  buildozer.spec
  main.py
  pong.kv

最佳答案

这通常是因为您不小心在 APK 中包含了额外的文件。如果您不知道它们可能是什么,请解压缩 apk,在其中找到 assets/private.mp3 文件,然后解压(它实际上是一个 tar 存档)。您找到的内容应该是您在 APK 中包含的所有内容,因此您可以检查它们是否符合您的预期。

关于android - 使用 buildozer kivy 的 800mb apk 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47377380/

相关文章:

android - 当 Active Android 包含在库中时,无法解析 Gradle 中的 Active Android 依赖项

android - 设置 ADT Eclipse

Python pandas groupby 在多列上聚合,然后旋转

python - 使用 beautifulsoup 抓取 Reddit 上的嵌套评论

python - 如何为字符串的最终出现创建正则表达式

java - 如何向所有在 Firebase 注册的用户发送推送通知?

java - 如何以特定方式以编程方式居中对齐绘制的对象

python - 如何使用 Python 将用户添加到 LDAP 组?

python - 如何获得数据框的简单散点图(最好使用 seaborn)

python-3.x - OpenCV 无法打开 *.mp4 文件