Is there a way to automate the android sdk installation?

后端 未结 12 2252
鱼传尺愫
鱼传尺愫 2020-11-27 08:41

Now I have to download and install the Android SDK and AVD Manager, and then install the APIs, tools through the UI. Is there a way to automate this process?

相关标签:
12条回答
  • 2020-11-27 09:32

    Starting with Android Plugin for Gradle version 2.2.0, missing SDK components get downloaded automatically.

    0 讨论(0)
  • 2020-11-27 09:37

    Yet another script to download only needed, non-{obsolute,source,emulator-image,doc} packages:

    #!/bin/bash
    set -e
    
    # cd into where tools/android can be found
    if [[ -d "$ANDROID_HOME" ]]; then
      cd "$ANDROID_HOME"
    elif [[ -x "$(dirname "$0")/tools/android" ]]; then
      cd "$(dirname "$0")"
    else
      echo "FAILED: Cannot find ANDROID_HOME/tools/android"
      exit 1
    fi
    
    android () {
      "$(dirname $0)/tools/android" "$@"
    }
    
    needed_packages () {
      android list sdk -u -s -e         \
        | grep '^id:'                   \
        | cut -d'"' -f2                 \
        | grep -v 'source'              \
        | grep -v 'sys-img'             \
        | grep -v 'doc'                 \
        | paste -d, -s -
    }
    
    main () {
      (while : ; do
      echo 'y'
      sleep 1
      done) | android update sdk -u -s -a -t "$(needed_packages)"
    }
    
    main
    

    Some parts are taken from other answers in this thread.

    0 讨论(0)
  • 2020-11-27 09:38

    This didn't work for me...

    echo "y" | android ....
    

    so I ended up here:

    expect -c '
    set timeout -1   ;
    spawn sudo /opt/android-sdk/tools/android update sdk -u; 
    expect { 
        "Do you accept the license" { exp_send "y\r" ; exp_continue }
        eof
    }
    '
    
    0 讨论(0)
  • 2020-11-27 09:38

    I got frustrated with this as well and built a Gradle plugin named com.quittle.setup-android-sdk that will detect and install what you need. It works on Windows, OSX, and Linux and doesn't require any additional dependencies if you build with Gradle.

    If you're interested you can checkout my docs on it here: https://github.com/quittle/gradle-setup-android-sdk

    0 讨论(0)
  • 2020-11-27 09:39

    I put together a ruby script that downloads and install the SDK without prompting which might help. https://github.com/ayvazj/andenv

    0 讨论(0)
  • 2020-11-27 09:47

    To automate the sdkmanager.bat --licenses prompt away on Windows (say you're installing via automation for build infrastructure)... Don't run it. Don't waste time trying to figure out how to pipe y into it. I tried; abject fail.

    Rather - run it one time, yourself, and take note that it generates files into c:\android\android-sdk\licenses (where you're running c:\android\android-sdk\tools\bin\sdkmanager.bat - your install root may vary).

    Take those files, and place them somewhere you can grab them from in your automated setup scripts. Personally, ansible is my poison, so:

    # Note to future-us:
    # These are magical files generated by running `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses`
    # This, delightfully, is interactive, and wants to _actually_ read the keyboard buffer.
    # That's reputedly possible via SendKeys. I elected to not try that.
    # So, instead:
    # 1) remote to an instance like a cave-dweller
    # 2) run `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses` in a prompt.
    # 3) _actually type_ `y` however many godforsaken times you need to.
    # 4) meticulously harvest `c:/android/android-sdk/licenses/*` to this task.
    #    (you don't need the newline that they thoughtfully put before the hash in each file).
    - name: set up android licenses by hand
      win_lineinfile:
        path: c:/android/android-sdk/licenses/{{ item.name }}
        line: "{{ item.line }}"
        create: true
      with_items:
        - {name: "android-googletv-license", line: "SOME HASH"}
        - {name: "android-sdk-license", line: "SOME OTHER HASH"}
        ...
    
    0 讨论(0)
提交回复
热议问题