如何从包中创建Kivy APK? [英] How do you create a kivy apk from a package?
问题描述
我有一个简单的python/kivy软件包,我希望从其中使用Buildozer创建一个Android APK.根目录下的软件包的组织方式为:
I have a simple python/kivy package from which I wish to create an android APK using Buildozer. The package from the root is organised as:
.
├── bin
│ ├── kivy_test-0.1-debug.apk
│ └── myapp-0.1-debug.apk
├── buildozer.spec
├── __init__.py
└── kivy_app
├── __init__.py
├── __main__.py
└── source
├── main.py
└── version.py
main.py模块是:
The module main.py is:
from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.uix.button import Label
from kivy.lang import Builder
from version import VERSION
root = Builder.load_string('''
<MainFrame>:
BoxLayout:
orientation: 'vertical'
Label:
text: 'Hola mundo!'
Label:
text: root.version
''')
class MainFrame(Screen):
version = 'Version: %s' % VERSION
def __init__(self, **kwargs):
super(MainFrame, self).__init__(**kwargs)
class BasicApp(App):
def build(self):
return MainFrame()
if __name__ == '__main__':
BasicApp().run()
version.py是
version.py is
__all__ = 'VERSION'
VERSION = '0.0.2'
和_
main _
.py是
and _
main_
.py is
from .source.main import BasicApp
def main():
BasicApp().run()
if __name__ == "__main__":
main()
我遇到的问题是,当我通过键入来运行模块时
The problem that I have is that when I run the module by typing
python -m kivy_app
在根目录中,我需要添加行
in the root directory I need to have the line
from .version import VERSION
在main.py中(请注意版本之前是.").
in main.py (note there is '.' before version).
另一方面,当我从根目录构建android apk时,buildozer.spec使用以下行:
On the other hand, when I build the android apk from the root directory the buildozer.spec uses the line:
# (str) Source code where the main.py live
source.dir = ./kivy_app/source
当然,它正在调用这些行:
and of course it is invoking the lines:
if __name__ == '__main__':
BasicApp().run()
在main.py中.
在这种情况下,将模块视为未包装在模块中,因此需要以下行:
In this case the module is treated as if it is not in a package and so needs the line:
from version import VERSION
(在这种情况下,import语句中的版本之前没有'.')
(In this case no '.' before version in the import statement)
如何解决此冲突?
推荐答案
此解决方案与将_
main _
.py复制到main.py并替换该行冲突:
The solution to this conflict it to copy _
main_
.py to main.py and to replace the line:
from .source.main import BasicApp
具有:
from source.main import BasicApp
在buildozer.spec中替换:
In buildozer.spec replace:
source.dir = ./kivy_app/source
具有:
source.dir = ./kivy_app
树现在是:
.
├── bin
│ ├── kivy_test-0.1-debug.apk
│ └── myapp-0.1-debug.apk
├── buildozer.spec
├── __init__.py
└── kivy_app
├── __init__.py
├── __main__.py
├── main.py
└── source
├── main.py
└── version.py
这篇关于如何从包中创建Kivy APK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!