Automatically accept all SDK licences

后端 未结 30 1778
感情败类
感情败类 2020-11-22 16:35

Since gradle android plugins 2.2-alpha4:

Gradle will attempt to download missing SDK packages that a project depends on

Which

相关标签:
30条回答
  • 2020-11-22 17:19

    Here is my Docker setup.
    You can follow from a plain Linux environment.

    Note that yes | and --licenses --sdk_root=${ANDROID_HOME} clauses.
    It seems sdkmanager --update reverts agreements, so yes | is appeared twice.

    FROM openjdk:8
    # Install dev-essential(gnumake)
    RUN apt update
    RUN apt install -y build-essential
    # Set ENV
    ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" \
        ANDROID_HOME="/usr/local/android-sdk" \
        ANDROID_VERSION=28 \
        ANDROID_BUILD_TOOLS_VERSION=28.0.3 \
        GRADLE_VERSION=4.10.3 \
        NDK_VERSION=r16b
    # Download Android SDK
    RUN mkdir "$ANDROID_HOME" .android \
        && cd "$ANDROID_HOME" \
        && curl -o sdk.zip $SDK_URL \
        && unzip sdk.zip \
        && rm sdk.zip \
        && yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses --sdk_root=${ANDROID_HOME}
    # Install Android Build Tool and Libraries
    RUN $ANDROID_HOME/tools/bin/sdkmanager --update
    RUN yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
        "platforms;android-${ANDROID_VERSION}" \
        "platform-tools" --sdk_root=${ANDROID_HOME}
    # Install Gradle
    RUN wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
    RUN mkdir /opt/gradle
    RUN unzip gradle-${GRADLE_VERSION}-all.zip -d /opt/gradle
    ENV PATH=${PATH}:/opt/gradle/gradle-${GRADLE_VERSION}/bin
    # Install NDK
    RUN wget https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux-x86_64.zip
    RUN mkdir /opt/ndk-bundle
    RUN unzip android-ndk-${NDK_VERSION}-linux-x86_64.zip -d /opt/ndk-bundle
    ENV PATH=${PATH}:/opt/ndk-bundle
    
    RUN mkdir /application
    WORKDIR /application
    
    0 讨论(0)
  • 2020-11-22 17:20

    The android tool is deprecated and you should use the sdkmanager instead. sdkmanager also writes the licenses file when you first accept it. The license changes depending on which SDK you are using so even though the command

    echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
    

    works on some systems. It won't work on all. Some SDK installs expect to license file to end without a newline in the file so try adding a -n to the echo command.

    echo -n -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
    

    If that isn't working you can try using the base64 encoding instead.

    So to discover my license:

    $> rm ${ANDROID_HOME}/
    $> unzip tools_r25.2.3-linux.zip -d ${ANDROID_HOME}
    $> ${ANDROID_HOME}/tools/bin/sdkmanager "system-images;android-23;default;x86_64"
    

    It'll prompt you to accept the license. After accepting it'll copy it to ${ANDROID_HOME}/licenses/android-sdk-license. To ensure you always get exactly what is written use base64.

    $> base64 ${ANDROID_HOME}/licenses/android-sdk-license
    Cjg5MzNiYWQxNjFhZjQxNzhiMTE4NWQxYTM3ZmJmNDFlYTUyNjljNTU=
    

    Then you can use base64 -d recreate the file exactly.

    $> echo Cjg5MzNiYWQxNjFhZjQxNzhiMTE4NWQxYTM3ZmJmNDFlYTUyNjljNTU= | base64 -d > ${ANDROID_HOME}/licenses/android-sdk-license
    

    You can verify if the file written is what is expected by running a sha1sum on it.

    $> sha1sum ${ANDROID_HOME}/licenses/android-sdk-license
    da6b80c9c47b41c0bf7032938e7137a58a3dc249
    
    0 讨论(0)
  • 2020-11-22 17:20

    I had the same error while using Cordova.

    The problem was due to the fact that I installed Android Sdk through Android Studio and through apt with apt install android-sdk adb. And Cordova was calling the files installed through apt instead of the files in my home directory.

    It worked once I changed the path to SDK in bash:

    # Change path
    export ANDROID_HOME="$HOME/Android/Sdk/"
    echo "Android home = $ANDROID_HOME"
    # Accept licenses
    eval "${ANDROID_HOME}/tools/bin/sdkmanager --licenses"
    # Run Cordova
    cordova build android
    

    Then I removed the system files that weren't used anymore: apt remove android-sdk adb.

    0 讨论(0)
  • 2020-11-22 17:21

    AndroidSDK can finally accept licenses.

    yes | sdkmanager --licenses
    

    EDIT:

    as pointed out in the comments by @MoOx, on macOS, you can do

    yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses

    as pointed out in the comments by @pho, @mikebridge and @ Noitidart on Windows, you can do

    cmd.exe /C"%ANDROID_HOME%\tools\bin\sdkmanager.bat --licenses"

    be sure to install java before

    0 讨论(0)
  • 2020-11-22 17:21

    For an error message about SDK api number 25:

    android update sdk --no-ui --all --filter build-tools-25.0.1,android-25,extra-android-m2repository

    0 讨论(0)
  • 2020-11-22 17:21

    cd $ANDROID_HOME/tools/bin yes | ./sdkmanager --update

    or

    yes | $ANDROID_HOME/tools/bin/sdkmanager --update

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