13

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.

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

2 Answers2

5

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

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' {} \;

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.

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
albodelu
  • 7,931
  • 7
  • 41
  • 84
  • Before asking the question, I tried to parse the output, but It's more difficult and error-prone than reinventing the wheel. Parsing XMLs is more reliable for me. Good answer, but it doesn't answer my question. –  May 28 '17 at 17:07
  • I know, my point is to avoid future bugs each time Google changes something. About your doubt, I think that path is reliable to check, and also the file existence to check if it's installed. – albodelu May 28 '17 at 17:21
3

You must do 2 separate work to done:

  1. Parse giving xmls from urls like (https://dl.google.com/android/repository/repository2-1.xml)
  2. Read files description in every folder in your SDK path

for example: in C:\Program Files (x86)\Android\android-sdk\platforms\android-23 in my laptop there is file with source.properties name with following contents:

Pkg.Desc=Android SDK Platform 6.0
Pkg.UserSrc=false
Platform.Version=6.0
Platform.CodeName=
Pkg.Revision=3
AndroidVersion.ApiLevel=23
Layoutlib.Api=16
Layoutlib.Revision=3
Platform.MinToolsRev=22

there is source.properties file in every folder. I hope this helps you ;)

Yashar Aliabbasi
  • 2,663
  • 1
  • 23
  • 35
  • How that will it help me to check if package is installed? The info on source.properties is useful. How can it help me? Do I have to check if file exists? Additionally, XMLs have a attribute called `path`, Will checking paths existence (replacing `;` with `\`) a reliable way to check if installed? –  May 28 '17 at 16:21