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

当前回答

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

其他回答

使用Android Studio的Ubuntu工作解决方案 下面是Ubuntu和Debian的工作过程:

install Android studio as desribed in their website https://developer.android.com/studio/install run : flutter config --android-studio-dir <location of android studio> then flutter config --android-sdk /home/user/Android/Sdk (this is the default location of the SDK) add the bin to your PATH PATH=$PATH:/home/user/Android/Sdk/tools/bin/ Afterwards, run : flutter doctor --android-licenses and accept all licences To check if everything is ok run the doctor in verbos mode as following : flutter doctor -v

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

同样的问题,通过谷歌来的。 根据AndroidStudio Archive,今天是4.1版本的发布日。 我想这不是巧合。

这个完全不相关的指南有一个针对linux的老版本sdk-tools的硬链接。 对于其他操作系统,可以将url更改为windows或mac。我现在就用它来解决问题。

(这应该是一个评论而不是一个解决方案)

简单的解决方案:

打开Android Studio工具菜单, SDK管理器在窗口中出现 上面是内嵌板, 选择SDK工具面板勾选Android SDK命令行工具 选择窗口底部附近的Apply按钮

Unity 2018文档中的这一页也很好地解释了解决这个问题的方法,包括以下几点:

在没有Android Studio的情况下安装Android SDK。 “警告:无法创建设置”和“java.lang.IllegalArgumentException”的解决方案 Android Studio 3.6或更新版本的诀窍。 关于Java 9或更高版本的警告,JDK必须是版本8。

https://docs.unity3d.com/2018.4/Documentation/Manual/android-sdksetup.html