Check if Android SDK package is installed programmatically

前端 未结 2 1390
忘了有多久
忘了有多久 2021-01-11 14:29

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.

相关标签:
2条回答
  • 2021-01-11 14:44

    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
    
    0 讨论(0)
  • 2021-01-11 14:44

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

    0 讨论(0)
提交回复
热议问题