我使用新的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

当前回答

刚刚用IDE解决了这个问题,对我来说看起来很简单。(实际上这是重复之前的答案,但有图片)。只要安装sdk工具,一切都应该工作。

其他回答

由于有新的更新,文档中没有提到一些更改。在解压缩命令行工具包之后,您将得到的最上面的目录是cmdline-tools。将解压缩目录从cmdline-tools重命名为tools,并将其放在$C:/Android/cmdline-tools下

现在它看起来像$C:/Android/cmdline-tools/tools

它会完美地工作。

混合了Jing Li和caller9的回答,这是我的脚本:

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

before_script:
  - apt-get update --yes
  - apt-get install --yes wget tar unzip lib32stdc++6 lib32z1
  - export ANDROID_HOME=${PWD}android-home
  - install -d $ANDROID_HOME
  - wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
  - pushd $ANDROID_HOME
  - unzip -d cmdline-tools cmdline-tools.zip
  - popd
  - export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
  - sdkmanager --version
  - set +o pipefail
  - yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses
  - set -o pipefail
  - sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
  - sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
  - sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"
  - export PATH=$PATH:${ANDROID_HOME}/platform-tools/
  - chmod +x ./gradlew
[...]

我想分享一下我的经验。

首先,我试图解释为什么目录结构必须看起来 在这个答案中显示的方法- 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

这里总结了几篇有用的文章,对于想要快速片段的人,例如插入Dockerfile,下面的脚本对我来说很有用:

RUN mkdir -p /opt/android/cmdline-tools/latest \
    && cd /opt/android/cmdline-tools/latest \
    && wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip \
    && bsdtar --strip-components=1 -xvf commandlinetools-linux-6858069_latest.zip \
    && yes | bin/sdkmanager --licenses \
    && bin/sdkmanager "build-tools;29.0.2" "platforms;android-29" \
    && rm commandlinetools-linux-6858069_latest.zip

It just requires bsdtar to be installed (it's usually packaged in popular distributions). Android platform/build tools version 29 are installed, and Android sdk root will be then located in /opt/android. While this setup works for me without warnings as it is, I have an issue when reinstalling packages already installed, or possibly installing different version of the packages: it clashes with packages already present and create bogus directories in the sdk root, with -2, -3 suffixes. These directories are then ignored, and warnings like Observed package id 'emulator' in inconsistent location are printed, so this behavior is definitely not desirable. If you have a fix for that please write it in the comments or, if you are confident enough, just edit the script with the exact fix.

对于那些在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