{"id":17084,"date":"2023-12-15T11:06:38","date_gmt":"2023-12-15T03:06:38","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=17084"},"modified":"2023-12-15T11:06:38","modified_gmt":"2023-12-15T03:06:38","slug":"python%e5%8f%af%e4%bb%a5%e5%88%b6%e4%bd%9c%e5%ae%89%e5%8d%93app","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/17084\/","title":{"rendered":"python\u53ef\u4ee5\u5236\u4f5c\u5b89\u5353app"},"content":{"rendered":"

Python\u4e0d\u662f\u4e00\u79cd\u539f\u751f\u7684\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u8bed\u8a00\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u521b\u5efa Android \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u6846\u67b6\u4e2d\u7684\u4e00\u4e9b\u5e93\u6216\u5de5\u5177\u6765\u7f16\u5199Android\u5e94\u7528\u7a0b\u5e8f\uff0c\u6700\u6d41\u884c\u7684\u662fKivy\u548cPyQt\u3002\u8fd9\u4e9b\u6846\u67b6\u4f7f\u7528Python\u8bed\u8a00\u6765\u8bbe\u8ba1\u7528\u6237\u754c\u9762\uff0c\u5e76\u751f\u6210Android APK\u6587\u4ef6\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u4f7f\u7528Kivy\u6846\u67b6\u521b\u5efaAndroid\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u4e9b\u6b65\u9aa4:<\/p>\n

1.\u5b89\u88c5Android SDK:<\/p>\n

\u6211\u4eec\u9700\u8981\u5b89\u88c5Android SDK\uff08\u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305\uff09\u6765\u5f00\u53d1Android\u5e94\u7528\u7a0b\u5e8f\u3002 Android SDK\u5305\u62ecAndroid\u5e73\u53f0\u5de5\u5177\uff0cAndroid Debug Bridge\uff08ADB\uff09\u548cFastboot\u5de5\u5177\u7b49\u7b49\u3002<\/p>\n

2.\u5b89\u88c5Java SE Development Kit\uff08JDK\uff09\uff1a<\/p>\n

JDK\u662fJava\u7f16\u7a0b\u8bed\u8a00\u7684\u5f00\u53d1\u5de5\u5177\u5305\u3002 Android\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528Java\u7f16\u5199\uff0c\u56e0\u6b64\u9700\u8981\u5b89\u88c5JDK\u3002<\/p>\n

3.\u5b89\u88c5Kivy\uff1a<\/p>\n

Kivy\u662f\u57fa\u4e8ePython\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u7528\u4e8e\u5f00\u53d1\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\uff0c\u5305\u62ec Android\u548ciOS\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

4.\u521b\u5efaAndroid\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Kivy\u5de5\u5177\u6765\u521b\u5efaAndroid\u5e94\u7528\u7a0b\u5e8f\u3002\u4e00\u4e2a\u7b80\u5355\u7684HelloWorld\u6837\u4f8b\u5b9e\u73b0\u4e86\u5728Android\u8bbe\u5907\u4e0a\u7684\u4e00\u4e2a\u6309\u94ae\u548c\u6587\u672c\u6846\u3002 <\/p>\n

“`python<\/p>\n

from kivy.app import App<\/p>\n

from kivy.uix.button import Button<\/p>\n

from kivy.uix.gridlayout import GridLayout<\/p>\n

class HelloWorldApp(App):<\/p>\n

def build(self):<\/p>\n

layout = GridLayout(cols=1)<\/p>\n

btn = Button(text=”Hello World”)<\/p>\n

layout.add_widget(btn)<\/p>\n

return layout<\/p>\n

HelloWorldApp().run()<\/p>\n

“`<\/p>\n

5.\u6784\u5efaAPK\uff1a<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Buildozer\u5de5\u5177\u5c06Kivy\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3aAndroid APK\u3002Buildozer\u5de5\u5177\u4f7f\u7528buildozer.spec\u8fc7\u7a0b\u6587\u4ef6\u6765\u5b9a\u4e49Android\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u3001\u4f9d\u8d56\u9879\u548cPython\u4ee3\u7801\u3002\u6211\u4eec\u53ef\u4ee5\u5728buildozer.spec\u6587\u4ef6\u4e2d\u4e3a\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u6307\u5b9a\u4f9d\u8d56\u9879\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e9b\u5176\u4ed6\u53c2\u6570\u3002\u4ee5\u4e0b\u662fbuildozer.spec\u6587\u4ef6\u7684\u793a\u4f8b: <\/p>\n

“`<\/p>\n

<\/figure>\n<\/p>\n

ini<\/p>\n

[app]<\/p>\n

# (str) Title of your application<\/p>\n

title = HelloWorld<\/p>\n

# (str) Package name<\/p>\n

package.name = helloworld<\/p>\n

# (str) Package domain (needed for android\/ios packaging)<\/p>\n

package.domain = org.test.helloworld<\/p>\n

# (int) App version<\/p>\n

version = 0.1<\/p>\n

# (str) Filename of your main.py script<\/p>\n

f\u5b89\u5353APP\u5f00\u53d1<\/a>ilename = main.py<\/p>\n

# (str) Application icon<\/p>\n

icon.filename = helloworld.png<\/p>\n

# (list) Permissions<\/p>\n

android.permissions = INTERNET<\/p>\n

# (list) List of service to declare<\/p>\n

android.services =<\/p>\n

# (list) List of features to declare<\/p>\n

android.features =<\/p>\n

# (s\u5b89\u5353app<\/a>tr) Orientation<\/p>\n

orientation = portrait<\/p>\n

# (bool) Keep the source code on the target machine.<\/p>\n

keep.source = 1<\/p>\n

# (str) Supported orientation (choices: portrait, landscape or all)<\/p>\n

# Android only<\/p>\n

orientation = portrait<\/p>\n

# (list) List of packaging options<\/p>\n

# Custom source example<\/p>\n

# requirements.source.kivy = git+https:\/\/github.com\/kivy\/kivy.git@master<\/p>\n

requirements = kivy<\/p>\n

“`<\/p>\n

6.\u8fd0\u884cAPK:<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u8fd0\u884c\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8fAPK\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u53ef\u4ee5\u5728Android\u8bbe\u5907\u4e0a\u5b89\u88c5\u548c\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Python\u4e0d\u662f\u4e00\u79cd\u539f\u751f\u7684\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u8bed\u8a00\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u521b\u5efa Android \u5e94\u7528\u7a0b\u5e8f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u6846\u67b6\u4e2d\u7684\u4e00\u4e9b\u5e93\u6216\u5de5\u5177\u6765\u7f16\u5199Android\u5e94\u7528\u7a0b\u5e8f\uff0c\u6700\u6d41\u884c\u7684\u662fKivy\u548cP<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[23477,23476,14,301,171],"class_list":["post-17084","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-app-h5-","tag-app","tag-14","tag-301","tag-171"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/17084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=17084"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/17084\/revisions"}],"predecessor-version":[{"id":17153,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/17084\/revisions\/17153"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=17084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=17084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=17084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}