Android Command line tools sdkmanager always shows: Warning: Could not create settings

这一生的挚爱 提交于 2020-03-17 09:57:09

问题


I use the new Command line tools of android because the old sdk-tools repository of android isn't available anymore. So I changed my gitlab-ci to load the commandlintools. But when I try to run it I get the following error:

Warning: Could not create settings
java.lang.IllegalArgumentException
    at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.<init>(SdkManagerCliSettings.java:428)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:152)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:134)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:57)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)

I already tried executing those commandy by hand, but I get the same error. Also if i run sdkmanager --version, the same error occurs. My gitlab-ci looks like:

image: openjdk:9-jdk

variables:
  ANDROID_COMPILE_SDK: "29"
  ANDROID_BUILD_TOOLS: "29.0.3"
  ANDROID_SDK_TOOLS:   "6200805"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
  - unzip -d android-sdk-linux android-sdk.zip
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
  #- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
  - chmod +x ./gradlew
  # temporarily disable checking for EPIPE error and use yes to accept all licenses
  - set +o pipefail
  - yes | android-sdk-linux/tools/bin/sdkmanager --licenses
  - set -o pipefail

stages:
  - build
  - test

lintDebug:
  stage: build
  script:
    - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint

assembleDebug:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
    - app/build/outputs/

debugTests:
  stage: test
  script:
    - ./gradlew -Pci --console=plain :app:testDebug

回答1:


This appears to be a bug with the way sdkmanager locates the SDK installation folder.

A work-around is to set the flag --sdk_root. You can move ANDROID_HOME declaration higher, then use it with the subsequent commands.

 - export ANDROID_HOME=$PWD/android-sdk-linux
 - yes | android-sdk-linux/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} --licenses
 - android-sdk-linux/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null

Also, moved blanket license acceptance command to the first command to clean up the echo y parts.

Oddly enough if you run sdkmanager --sdk_root=${ANDROID_HOME} "tools" it will upgrade tools from 3.6.0 to 26.1.1 and sdkmanager no longer has this issue. This update takes time and bandwidth and isn't exactly necessary with the work-around.




回答2:


Downloading the new cmdline-tools from Android Developer website require the following directory structure to be respected. I'll be link the screenshot of directory tree.

Required directory structure




回答3:


For those who struggled with installing Android Command Line Tools for Appium on Windows 10/x64 just do as following:

  1. Download latest Command line tools from android i.e. commandlinetools-win-6200805_latest.zip
  2. Unzip the downloaded file
  3. Create directory for storing commandline tools somewhere on your disk, with following path included: android/cmdline-tools/latest Basically when You unzip this Cmd line tools, just rename tools directory to latest and make sure You put this latest folder in android/cmdline-tools directory somewhere on your disk
  4. Create ANDROID_HOME environment variable for directory that stores the cmdline tools directory location like: C:\YourLocationWhereYouStoreTheDirectory\android\cmdline-tools\latest
  5. Create new entry in Path environment variable as %ANDROID_HOME%\bin



回答4:


Got the same issue, came here by Google. According to the AndroidStudio Archive, today was the release of 4.1. I suppose that's no coincidence.

This completely unrelated guide has a hardlink for an older version of the sdk-tools for linux. You can change the url to windows or mac for other OSs. I'll use that as a hotfix for now.

(that was supposed to be a comment not a solution)




回答5:


I found the solution to use the latest command-line tools following those steps:

1 - Extracting the Command-line tools into a folder with this structure: e.g.: $HOME/Development/android/cmdline-tools/latest (this folder must contain lib, bin, notice.txt and source.properties)

2 - Defining ANDROID_HOME as an environment variable:

ANDROID_HOME="$HOME/Development/android/cmdline-tools/latest"

3 - Loading it on PATH:

PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/lib:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools"


来源:https://stackoverflow.com/questions/60440509/android-command-line-tools-sdkmanager-always-shows-warning-could-not-create-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!