在Python中抓取AndroidManifest.xml时的回溯非零退出状态

时间:2019-01-30 15:45:21

标签: android python

我正在尝试从AndroidManifest.xml文件中抓取信息(版本和大小),这是我的代码:

import os
from subprocess import run, PIPE
import json

def createmanifestjson(pkg_name):
 def getVersionName(pkg_name):
    result = run([
             '/Users/.../Library/Android/sdk/build-tools/28.0.3/aapt',
             'dump', 'badging', pkg_name],
        stdout=PIPE, stderr=PIPE, check=True,
        universal_newlines=True)
    version = result.stdout.split("versionName='")[1].split("'")[0]
    print(version)
    return(version)

 def getapksize(pkg_name):
    apkpath = "/Users/.../Downloads/"
    if (os.path.isfile(apkpath + pkg_name+".apk")):
        apksize = os.stat(apkpath + pkg_name+ ".apk").st_size
        print(str(apksize/1000000) + " MB")
        return apksize
    else:
        print("Varies with device")
        return("Varies with device")



 manifestData = {}
 manifestData['appdata'] = []



 manifestData['appdata'].append({
 'versionName' : getVersionName(pkg_name),
 'size': getapksize(pkg_name[:-4]),

 })


jsonfile = "manifestdata.json"
with open(jsonfile, 'a+') as outfile:
    json.dump(manifestData, outfile)


createmanifestjson("com.ubercab.apk")
createmanifestjson("com.buzzfeed.android.apk")

该代码适用于第一个APK,但第二个则停止,并且我的退出状态是:

  

回溯(最近一次通话最后一次):文件“ manifestinfos.py”,第61行,   在       createmanifestjson(“ com.buzzfeed.android.apk”)文件“ manifestinfos.py”,行40,位于createmanifestjson中       'versionName':getVersionName(pkg_name),文件“ manifestinfos.py”,第15行,位于getVersionName中       Universal_newlines = True)文件“ /Users/.../anaconda3/lib/python3.7/subprocess.py”,行468,正在运行       output = stdout,stderr = stderr)子进程CalledProcessError:命令'['/Users/.../Library/Android/sdk/build-tools/28.0.3/aapt',   'dump','badging','com.buzzfeed.android.apk']'返回非零退出   状态1。

为什么我的代码可用于某些apk时,我为何具有此非零退出状态?谢谢

0 个答案:

没有答案