Sunday, May 28, 2017

Check if Android SDK package is installed programmatically

Leave a Comment

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.

3 Answers

Answers 1

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 

Answers 2

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 ;)

Answers 3

In remotePackage, the attribute path is both the installation path and a identifier (ID).

  1. Convert ; to \ to make it a real path.
  2. Download the package.
  3. Unzip the package in the path.

You can use path to check folder existence (Convert ; to \).

To uninstall a package

  1. Delete the path (it's too simple).

I hope it helped you.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment