Kivy buildozer:如何部署到特定的Android设备

时间:2020-01-17 11:43:22

标签: kivy buildozer

我有多个连接到PC的设备(AVD和硬件),但是我想使用buildozer部署到特定设备。如果无法断开其他设备的连接怎么办?

2 个答案:

答案 0 :(得分:0)

Buildozer通过adb安装到android。因此,您必须检查adb的文档,并检查在buildozer启动脚本中如何对其进行修改。

http://www.appsdeveloperblog.com/install-apk-on-device-adb/https://pypi.org/project/buildozer/ 认为命令会像

buildozer android deploy adb --s <DEVICE_NAME>

答案 1 :(得分:0)

截至2020年1月18日:

似乎buildozer 1.0.1-dev0没有足够的灵活性来完成此任务。像buildozer android deploy adb -s <DEVICE_ID>这样的命令只会忽略DEVICE_ID,并在所有可用设备上安装apk。 有一个方便的buildozer serve命令,但这很慢,需要手动回答所有安全对话框。

直接使用adb是一个合理的选择,例如:

adb -s DEVICE_ID install -r your.apk

但是,如果有很多设备(armv7和x86),那么每次键入此命令都会很麻烦。所以我最后得到了一个放在项目目录中的脚本:

import sys
import subprocess

# TODO: edit your custom settings
ADB_EXE = "/home/your_username/Android/Sdk/platform-tools/adb"
APK_X86 = "/path/to/apk/x86/bin/your_project__x86-0.1-x86-debug.apk"
APK_ARMV7 = "/path/to/apk/armv7/bin/your_project__armeabi-v7a-0.1-armeabi-v7a-debug.apk"

DEVICES = {
    # DEVICE_PSEUDO_NAME: ("DEVICE_ID", "PATH_TO_APK")
    "pixtab": ("emulator-5554", APK_X86),
    "pix": ("emulator-5556", APK_X86),
    "nexus4": ("004a900e1b268111", APK_ARMV7),
    "nomi": ("SSI1216C111031288", APK_ARMV7),
}


def run():
    global ADB_EXE
    global DEVICES
    if len(sys.argv) == 1:
        print("Please, specify device.")
        return
    if sys.argv[1] == "list":
        # print all available android devices
        res = subprocess.check_output([ADB_EXE, "devices"])
        for line in res.splitlines():
            print(line)
        return

    dev_name = sys.argv[1]
    print(f"Selected device: {dev_name}")
    if dev_name not in DEVICES:
        print(f"Device is not in the list, skipping.")
        return

    dev_id, apk = DEVICES[dev_name]
    # "-r" means force install
    res = subprocess.check_output([ADB_EXE, "-s", dev_id, "install", "-r", apk])
    for line in res.splitlines():
        print(line)

    print(f"-- Deployment into {dev_id} complete.")


if __name__ == "__main__":
    run()

列出所有设备:

python3 dp.py list

要将特定的apk部署到特定的设备:

python3 dp.py YOUR_DEVICE_PSEUDO_NAME