python 执行adb 安装Apk

#encoding:utf-8
import os,time,re
a='adb devices'
b=os.popen(a).readlines()
print(b)
l=[]
for sn in b:
    if 'device' in sn and 'List' not in sn:
        a=sn.split('\t')[0]
        l.append(a)
print(l)
 
for mob in l:
    path ='C:\\Users\\akm\\Desktop\\zgt\\e.apk'
    print(path)

    size_str = os.popen('adb shell wm size').read()
    print(size_str)
    m = re.search(r'(\d+)x(\d+)', size_str)
    height=m.group(2)
    width=m.group(1)

    print(width+"x"+height)
    
    a = 'adb -s {} install -r {}'.format(mob,path)
    print(a)
    print('安装进行中... ')
    bb=os.popen(a).readlines()  
    print(bb)
    if 'Success\n' in bb:
         print(mob+'安装完成')
    else:
         print(mob+'安装失败')
    os.system('adb shell input keyevent 3')
print('完成')

 

 

window bat.bat

@echo off
echo -------------------------开始安装------------------------------- 
call adb install -r xxx_release_1.apk 
call adb shell dumpsys package com.xxx.xxx| findstr versionName 
echo -------------------------检查版本号,按任意键关机------------------------------- 
pause
echo -------------------------关机-------------------------------
call adb shell reboot -p
echo -------------------------完成,按任意键重新开始-------------------------------
pause
cls
call bat.bat

 

aikongmeng CSDN认证博客专家 RxJava 性能优化 Android Jetpack
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( T | o ) ( Y | o | u | t | h | , | T | o ) ( S | i | m | p | l | e | ! )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:上身试试 返回首页