我使用新的Android命令行工具,因为旧的Android sdk-tools库已经不可用了。所以我改变了我的gitlab-ci来加载commandlintools。但是当我尝试运行它时,我得到以下错误:

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长这样:

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

当前回答

Android Studio在安装命令行工具时是必要的,即使它不是你用来开发应用程序的编辑器。取消选中过时的包选项卡并下载工具就可以了;这应该可以解决许可证问题,你可以回到你最喜欢的IDE(如VS Code)。

其他回答

我想分享一下我的经验。

首先,我试图解释为什么目录结构必须看起来 在这个答案中显示的方法- https://stackoverflow.com/a/60460681/1758733。 https://stackoverflow.com/users/668455/tristan多次要求解释,所以希望我能澄清 下一个实验的情况:

1. unpack cmdline-tools to any path, for example c:\Android\tools;
2. create a folder for SDK, let it be c:\Android\SDK;
3. install cmdline-tools (yes, we install cmdline-tools again =)):
    c:\Android\tools\bin\sdkmanager --sdk_root=c:\Android\SDK "cmdline-tools;latest"
4. at this moment we can examine c:\Android\SDK and locate
    the path c:\Android\SDK\cmdline-tools\latest. If we compare
    this folder with the previous version c:\Android\tools we find out
    that they are identical. The new installed c:\Android\SDK\cmdline-tools\latest\sdkmanager works
    without --sdk_root argument so we could initially unpack cmdline-tools
    to cmdline-tools\latest.

可能会遇到另一个问题-卡在“.android/repositories.cfg无法加载”。

其他问题和事实:

1. QtCreator works with another sdkmanager that placed in SDK_ROOT/tools/bin
2. SDK_ROOT/tools/bin/sdkmanager works only with JDK 8
3. Java uses its own storage for certificates and it's not convinient usually.
    Thus one may want to use Windows certificate store. Unfortunately Grandle has the
    issue - https://stackoverflow.com/a/59056537 - so use the following:
    set JAVA_OPTS=-Djavax.net.ssl.trustStoreType=Windows-ROOT -Djavax.net.ssl.trustStore=NUL

总结一下Qt开发的配方可以组成:

1. download commandlinetools-win-6200805_latest.zip
2. extract cmdline-tools so there will be hierarchy
    SDKROOT
        - cmdline-tools
            - latest
                - bin
                    - sdkmanager.bat
                    - ...
                - lib
                - ...
3. install JDK 8. set JAVA_HOME=c:\path\to\java so that %JAVA_HOME%/bin/java.exe exists.
4. set JAVA_OPTS=-Djavax.net.ssl.trustStoreType=Windows-ROOT -Djavax.net.ssl.trustStore=NUL
5. NDK may be downloaded manually or installed with sdkmanager
6. install required components:
    SDKROOT\cmdline-tools\latest\bin\sdkmanager "tools" "build-tools;BUILD_TOOLS_VERSION" "platform-tools" "platforms;ANDROID_VERSION"
7. run qtcreator from console so JAVA_OPTS is taken into account (or set it globaly for windows user or even station)
8. tools -> options -> devices set paths to JDK 8, SDKROOT and NDK

对于那些在Windows 10/x64上为Appium安装Android命令行工具的人,请执行以下操作:

Download latest Command line tools from android i.e. commandlinetools-win-6200805_latest.zip Unzip the downloaded file 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 Create ANDROID_HOME environment variable for directory that stores the cmdline tools directory location like: C:\YourLocationWhereYouStoreTheDirectory\android\cmdline-tools\latest Create new entry in Path environment variable as %ANDROID_HOME%\bin

我们不再为每个命令执行传递参数——sdk_root,而是深入研究真正的原因。

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 (which is deprecated, we will use the term ANDROID_SDK_ROOT for the rest of the paragraph), 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.

将tools目录包装到cmdline-tools目录中将使其工作,并帮助您摆脱恼人的——sdk_root参数。但是其他部分呢?

这就是你要改变的。让我解释更多。

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_SDK_ROOT. Because later, when updating Android SDK, or installing more packages, the other packages will be placed under ANDROID_SDK_ROOT, but not under cmdline-tools. The final, complete ANDROID_SDK_ROOT 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_SDK_ROOT.

让我简单概括一下:

设置您首选的ANDROID_SDK_ROOT(就像以前一样) 下载并解压commandlinetools zip文件到名为cmdline-tools的目录中,该目录位于ANDROID_SDK_ROOT目录中 将目录$ANDROID_SDK_ROOT/cmdline-tools/tools/bin追加到环境变量PATH后,这样系统就知道在哪里可以找到sdkmanager

更新! ! ! !

自构建6858069 (Android SDK命令行工具3.0)以来,行为再次发生了变化:

After unzipping the package, the top-most directory you'll get is cmdline-tools. Rename the unpacked directory from cmdline-tools to tools, and place it under $ANDROID_SDK_ROOT/cmdline-tools, so now it should look like: $ANDROID_SDK_ROOT/cmdline-tools/tools. And inside it, you should have: NOTICE.txt bin lib source.properties. Actually according to the official Command-Line Tools doc, the tree structure should be android_sdk/cmdline-tools/version/bin/, but I've checked, using version or tools makes no difference here. For your environment variable PATH, I would recommend you to set like this: PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin, because after update later, you'll get the latest sdkmanager placed under $ANDROID_SDK_ROOT/cmdline-tools/latest/bin, put it in front will make it higher priority.

我找到了使用最新命令行工具的解决方案,以下步骤:

1 -将命令行工具提取到如下结构的文件夹: 例如:$ HOME /开发/ android / cmdline-tools /最新 (此文件夹必须包含lib, bin, notice.txt和source.properties)

2 -将ANDROID_HOME定义为环境变量:

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

3 -加载它的路径:

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

安装SDK(任何方法)的第一个要求是安装Java并设置JAVA_HOME路径。 然后,SDK命令行工具需要安装路径,否则会抛出NullPointerException。 要克服这个问题,只需传递你想要安装SDK的路径,参数为“——sdk_root” 如。Sdkmanager.bat "platform-tools" "platforms;android-"——sdk_root=