Check if Android SDK package is installed programmatically

前端 未结 2 1389
忘了有多久
忘了有多久 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
    

提交回复
热议问题