检查是否以编程方式安装了Android SDK软件包 [英] Check if Android SDK package is installed programmatically

查看:87
本文介绍了检查是否以编程方式安装了Android SDK软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为GUI独立的SDK Manager(Android SDK 25上已不存在)提供替代方案,我在Android Studio中发现了检索包所需的XML.

I'm making an alternative for the GUI stand-alone SDK Manager (it's gone on Android SDK 25), I've found in Android Studio the required XMLs to retrieve packages.

Android Repository  https://dl.google.com/android/repository/repository2-1.xml
Android System Images   https://dl.google.com/android/repository/sys-img/android/sys-img2-1.xml
Android TV System Images    https://dl.google.com/android/repository/sys-img/android-tv/sys-img2-1.xml
Android Wear System Images  https://dl.google.com/android/repository/sys-img/android-wear/sys-img2-1.xml
Glass Development Kit, Google Inc.  https://dl.google.com/android/repository/glass/addon2-1.xml
Google API add-on System Images https://dl.google.com/android/repository/sys-img/google_apis/sys-img2-1.xml
Google API with Playstore System Images https://dl.google.com/android/repository/sys-img/google_apis_playstore/sys-img2-1.xml
Google Inc. https://dl.google.com/android/repository/addon2-1.xml
Intel HAXM  https://dl.google.com/android/repository/extras/intel/addon2-1.xml
Offline Repo    file:/C:/Program%20Files/Android/Android%20Studio/plugins/sdk-updates/offline-repo/offline-repo.xml

我想检查安装了哪些软件包,哪些可以更新,哪些没有安装但可以下载.

I want to check what packages are installed, what are available for update and what aren't installed but available for download.

我知道如何解析,我完全不确定path属性是否是一种可靠的检查方法.

I know how to parse, I'm not sure at all if path attribute is a reliable way to check.

推荐答案

您不需要重新发明轮子.我将使用新的sdkmanager并向其中添加一个GUI.

You don't need to reinvent the wheel. I would use the new sdkmanager and add a GUI to it.

仅使用新命令行工具 sdkmanager 解析输出.来自此处的输出.

Only use sdkmanager, the new command line tool, and parse the output. Output from here.

此简单的命令行列出了已安装的软件包:

This simple command line lists the installed packages:

find ~/.android-sdk/ -name package.xml -exec sh -c 'eval $(xmllint --xpath "//*[local-name()='\'localPackage\'']/@path" $0) && echo $path' {} \;

您可以比较可用软件包的完整列表(由sdkmanager返回)和已安装软件包的列表(由此命令或sdkmanager返回),然后在此信息上添加GUI.

You can compare a full list of available packages (returned by sdkmanager) and the list of installed packages (returned by this command or sdkmanager), then add the GUI over this information.

要使用sdkmanager --list --verbose解析的替代输出,在此处此处

Alternative output to be parsed using sdkmanager --list --verbose explained here and here

./sdkmanager --list --verbose > tmp.txt

Info: Parsing /Users/albodelu/Library/Android/sdk/build-tools/19.1.0/package.xml
Info: Parsing /Users/albodelu/Library/Android/sdk/build-tools/21.1.2/package.xml
...
Info: Parsing /Users/albodelu/Library/Android/sdk/system-images/android-25/google_apis/x86_64/package.xml
Info: Parsing /Users/albodelu/Library/Android/sdk/tools/package.xml
Installed packages:
--------------------------------------
build-tools;19.1.0
    Description:        Android SDK Build-Tools 19.1
    Version:            19.1.0
    Installed Location: /Users/albodelu/Library/Android/sdk/build-tools/19.1.0

build-tools;21.1.2
    Description:        Android SDK Build-Tools 21.1.2
    Version:            21.1.2
    Installed Location: /Users/albodelu/Library/Android/sdk/build-tools/21.1.2
...
system-images;android-25;google_apis;x86_64
    Description:        Google APIs Intel x86 Atom_64 System Image
    Version:            4
    Installed Location: /Users/albodelu/Library/Android/sdk/system-images/android-25/google_apis/x86_64

tools
    Description:        Android SDK Tools
    Version:            26.0.2
    Installed Location: /Users/albodelu/Library/Android/sdk/tools

Available Packages:
--------------------------------------
add-ons;addon-google_apis-google-15
    Description:        Google APIs
    Version:            3

add-ons;addon-google_apis-google-16
    Description:        Google APIs
    Version:            4
...
system-images;android-25;google_apis;x86
    Description:        Google APIs Intel x86 Atom System Image
    Version:            4

system-images;android-25;google_apis;x86_64
    Description:        Google APIs Intel x86 Atom_64 System Image
    Version:            4

tools
    Description:        Android SDK Tools
    Version:            26.0.2
    Dependencies:
        patcher;v4
        emulator
        platform-tools Revision 20

done

这篇关于检查是否以编程方式安装了Android SDK软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆