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

当前回答

这里总结了几篇有用的文章,对于想要快速片段的人,例如插入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.

其他回答

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

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

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

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

它会完美地工作。

这里总结了几篇有用的文章,对于想要快速片段的人,例如插入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.

这里有一个非常基本和简单的解决方案 只需更改文件夹结构 将主文件夹名称更改为最新 然后创建一个名为cmdline-tools的文件夹 在cmdline中创建名为tools的新文件夹,并将bin和其他数据放在tools文件夹中 它看起来是这样的 用户最新\ \ cmdline-tools \工具

我搜索了很多,但它对我有用