Android命令行工具sdkmanager始终显示:警告:无法创建设置 [英] Android Command line tools sdkmanager always shows: Warning: Could not create settings

查看:815
本文介绍了Android命令行工具sdkmanager始终显示:警告:无法创建设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了android的新命令行工具,因为android的旧sdk-tools存储库不再可用.因此,我更改了gitlab-ci以加载commandlintools.但是,当我尝试运行它时,出现以下错误:

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)

我已经尝试过手动执行那些命令,但遇到相同的错误.另外,如果我运行sdkmanager --version,也会发生相同的错误. 我的gitlab-ci看起来像:

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

推荐答案

让我们深入研究真正的原因,而不是为每次执行单个命令都传递参数--sdk_root.

Instead of passing the argument --sdk_root for each single command execution, let's deep dive into the real cause.

Android SDK命令行工具1.0.0(6200805)开始,与 Android SDK 26.1.1(4333796)相反,tools目录层次结构已经变了. 以前它被放置在ANDROID_HOME内部,现在它仍被命名为tools(解压缩下载的 commandlinetools zip文件后唯一得到的东西),但是不同的是,您必须将其放置在您自己的名为cmdline-tools的目录中.名称cmdline-tools来自其程序包名称,您可以从列表程序包命令sdkmanager --list中获得该命令,其输出包括cmdline-tools;1.0 | 1.0 | Android SDK Command-line Tools.

Starting from Android SDK Command-line Tools 1.0.0 (6200805), in contrast to Android SDK 26.1.1 (4333796), the tools directory hierarchy has been changed. Previously it was placed right inside ANDROID_HOME, now it's still named as tools (the only thing you'll get after unpacking the downloaded commandlinetools zip file), but differently, you have to place it inside a directory called cmdline-tools on your own. The name cmdline-tools comes from its package name, where you can get from listing packages command sdkmanager --list, whose outputs include cmdline-tools;1.0 | 1.0 | Android SDK Command-line Tools.

cmdline-tools目录中包装tools目录将使其起作用,并帮助您摆脱烦人的--sdk_root参数.但是其他部分呢?

Wrapping tools directory inside cmdline-tools directory would make it work, and help you get rid of the annoying --sdk_root argument. But what about the other parts?

好吧,这就是您需要更改的所有内容.让我解释更多.

Well, that's all you have to change. Let me explain more.

  • 国王-sdkmanager生活在cmdline-tools/tools/bin内部,最好在PATH环境变量中设置
  • cmdline-tools不应设置为ANDROID_HOME.因为稍后,当更新Android SDK或安装更多软件包时,其他软件包将放在ANDROID_HOME下,而不是在cmdline-tools下.
  • 最终的,完整的ANDROID_HOME目录结构应如下所示,由许多子目录组成:build-toolscmdline-toolsemulatorlicensespatcherplatform-toolsplatformssystem-images.您可以轻松地指出build-toolscmdline-tools是兄弟姐妹,都位于父级ANDROID_HOME内.
  • The king - sdkmanager lives inside cmdline-tools/tools/bin, you'd better set in PATH environment variable
  • cmdline-tools should not be set as ANDROID_HOME. Because later, when updating Android SDK, or installing more packages, the other packages will be placed under ANDROID_HOME, but not under cmdline-tools.
  • The final, complete ANDROID_HOME directory structure should look like below, consist of quite a few sub-directories: build-tools, cmdline-tools, emulator, licenses, patcher, platform-tools, platforms, system-images. You can easily point out that build-tools and cmdline-tools are siblings, all sit inside the parent ANDROID_HOME.

让我以简单的方式回顾一下:

Let me recap in a simple way:

  • 设置您喜欢的ANDROID_HOME(就像以前一样)
  • 下载 commandlinetools zip文件并将其解压缩到名为cmdline-tools的目录中,该目录位于ANDROID_HOME
  • 内部
  • 将目录$ANDROID_HOME/cmdline-tools/tools/bin附加到环境变量PATH,以便系统知道在何处查找sdkmanager
  • Set your preferred ANDROID_HOME (just like before)
  • Download and unpack the commandlinetools zip file into a directory called cmdline-tools, which is inside ANDROID_HOME
  • Append the directory $ANDROID_HOME/cmdline-tools/tools/bin to environment variable PATH, so that the system knows where to find sdkmanager

这篇关于Android命令行工具sdkmanager始终显示:警告:无法创建设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆