{"id":19617,"date":"2024-03-18T11:58:27","date_gmt":"2024-03-18T03:58:27","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=19617"},"modified":"2024-03-18T11:58:27","modified_gmt":"2024-03-18T03:58:27","slug":"py%e6%96%87%e4%bb%b6%e6%89%93%e5%8c%85%e6%88%90apk%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2024\/03\/18\/py%e6%96%87%e4%bb%b6%e6%89%93%e5%8c%85%e6%88%90apk%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84\/","title":{"rendered":"py\u6587\u4ef6\u6253\u5305\u6210apk\u5982\u4f55\u5b9e\u73b0\u7684?"},"content":{"rendered":"

\u5c06Python\u6587\u4ef6\u6253\u5305\u6210APK\u662f\u4e00\u79cd\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3aAndroid\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\u3002Python\u662f\u4e00\u79cd\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u800cAndroid\u5e94\u7528\u7a0b\u5e8f\u662f\u4f7f\u7528Java\u7f16\u5199\u7684\u3002\u56e0\u6b64\uff0c\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3aJava\u4ee3\u7801\uff0c\u7136\u540e\u5c06\u5176\u7f16\u8bd1\u4e3aAndroid\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u79cd\u5c06Python\u6587\u4ef6\u6253\u5305\u6210APK\u7684\u65b9\u6cd5\u3002<\/p>\n

\u4e0b\u9762\u662f\u5c06Python\u6587\u4ef6\u6253\u5305\u6210APK\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

1. \u5b89\u88c5Kivy\u548cBuildozer<\/p>\n

Kivy\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u7684Python\u5e93\uff0c\u800cBuildozer\u662f\u4e00\u4e2a\u7528\u4e8e\u6253\u5305Python\u5e94\u7528\u7a0b\u5e8f\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002\u56e0\u6b64\uff0c\u9700\u8981\u5148\u5b89\u88c5\u8fd9\u4e24\u4e2a\u5de5\u5177\u3002<\/p>\n

2. \u7f16\u5199Python\u4ee3\u7801<\/p>\n

\u7f16\u5199Python\u4ee3\u7801\uff0c\u786e\u4fdd\u5b83\u80fd\u591f\u5728Kivy\u4e2d\u8fd0\u884c\u3002\u53ef\u4ee5\u5728Kivy\u7684\u5b98\u65b9\u6587\u6863\u4e2d\u627e\u5230\u793a\u4f8b\u4ee3\u7801\u3002\u8fd9\u91cc\u4ee5\u4e00\u4e2a\u7b80\u5355\u7684\u201cHello World\u201d\u5e94\u7528\u7a0b\u5e8f\u4e3a\u4f8b\uff1a<\/p>\n

“`<\/p>\n

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

from kivy.uix.label import Label<\/p>\n

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

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

return Label(text=”Hello World”)<\/p>\n

if __name__ == ‘__main__’:<\/p>\n

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

“`<\/p>\n

3. \u521b\u5efaBuildozer.spec\u6587\u4ef6<\/p>\n

Buildozer.spec\u6587\u4ef6\u662f\u4e00\u4e2a\u7528\u4e8e\u914d\u7f6e\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528buildozer init\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Buildozer.spec\u6587\u4ef6\u3002\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n

“`<\/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.example<\/p>\n

# (str) Source code where the main.py live<\/p>\n

source.dir\u8f6f\u4ef6\u4e00\u952e\u8f6cios<\/a> = .<\/p>\n

# (list) Source files to include (let empty to include all the files)<\/p>\n

source.include_exts = py,png,jpg,kv,atlas<\/p>\n

# (list) Application requirements<\/p>\n

# comma separated e.g. requirements = sqlite3,kivy<\/p>\n

requirement<\/p>\n

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

s = kivy<\/p>\n

[buildozer]<\/p>\n

# (int) Log level (0 = error only, 1 = info, 2 = dflutter ios \u6253\u5305\u53d1\u5e03<\/a>ebug (with command output))<\/p>\n

log_level = 2<\/p>\n

# (str) Path to the android ndk<\/p>\n

android.ndk_path = \/path\/to\/android\/ndk<\/p>\n

# (str) Path to the android sdk<\/p>\n

android.sdk_path = \/path\/to\/android\/sdk<\/p>\n

# (str) Android API to use<\/p>\n

android.api = 19<\/p>\n

# (str) Minimum API required<\/p>\n

android.minapi = 9<\/p>\n

# (str) Android NDK version to use<\/p>\n

android.ndk = 8c<\/p>\n

# (str) Python for android distribution to use<\/p>\n

android.python = 2.7<\/p>\n

# (list) List of inclusions using pattern matching<\/p>\n

include_patterns = assets\/*,images\/*.png<\/p>\n

# (list) List of exclusions using pattern matching<\/p>\n

exclude_patterns = license,README.md<\/p>\n

# (str) Application versioning (method 1)<\/p>\n

version = 0.1<\/p>\n

# (str) Application versioning (method 2)<\/p>\n

version.regex = __version__ = [‘”](.*)[‘”]<\/p>\n

version.filename = %(source.dir)s\/main.py<\/p>\n

# (list) Application requirements for optional SDK modules (comma separated)<\/p>\n

android.arch = x86<\/p>\n

# (str) OUYA Console category<\/p>\n

ouya.category = GAME<\/p>\n

# (str) Filename of OUYA Console icon<\/p>\n

ouya.icon.filename = %(source.dir)s\/data\/icon.png<\/p>\n

# (str) XML file to include as an intent filters in tag<\/p>\n

android.manifest.intent_filters = intent_filters.xml<\/p>\n

“`<\/p>\n

4. \u6253\u5305\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5728\u7ec8\u7aef\u4e2d\uff0c\u4f7f\u7528buildozer android debug\u547d\u4ee4\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u5c06\u4f7f\u7528Buildozer.spec\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u4fe1\u606f\u6765\u7f16\u8bd1\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

“`<\/p>\n

buildozer android debug<\/p>\n

“`<\/p>\n

5. \u5b89\u88c5\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5c06\u751f\u6210\u7684APK\u6587\u4ef6\u590d\u5236\u5230Android\u8bbe\u5907\u4e0a\uff0c\u5e76\u5728\u8bbe\u5907\u4e0a\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u4f7f\u7528adb install\u547d\u4ee4\u6765\u5b89\u88c5\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

“`<\/p>\n

adb install HelloWorld-0.1-debug.apk<\/p>\n

“`<\/p>\n

\u603b\u7ed3\uff1a<\/p>\n

\u5c06Python\u6587\u4ef6\u6253\u5305\u6210APK\u9700\u8981\u4f7f\u7528Kivy\u548cBuildozer\u8fd9\u4e24\u4e2a\u5de5\u5177\u3002\u4f7f\u7528Buildozer.spec\u6587\u4ef6\u6765\u914d\u7f6e\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u7684\u8bbe\u7f6e\uff0c\u7136\u540e\u4f7f\u7528buildozer android debug\u547d\u4ee4\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u3002\u6700\u540e\uff0c\u5c06\u751f\u6210\u7684APK\u6587\u4ef6\u590d\u5236\u5230Android\u8bbe\u5907\u4e0a\u5e76\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06Python\u6587\u4ef6\u6253\u5305\u6210APK\u662f\u4e00\u79cd\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3aAndroid\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\u3002Python\u662f\u4e00\u79cd\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u800cAndroid\u5e94\u7528\u7a0b\u5e8f\u662f\u4f7f\u7528Java\u7f16\u5199\u7684\u3002\u56e0\u6b64\uff0c\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3a<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[21764,116,12,849,21702],"topic":[],"class_list":["post-19617","post","type-post","status-publish","format-standard","hentry","category-kaifaapp","tag-ipa","tag-116","tag-12","tag-849","tag-21702"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/19617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=19617"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/19617\/revisions"}],"predecessor-version":[{"id":19634,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/19617\/revisions\/19634"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=19617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=19617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=19617"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=19617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}