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

当前回答

我在新Mac上下载独立命令行工具(commandlinetools-mac-6200805_latest)时就遇到了这种情况。

基于这里所有的答案,我能够让它像这样工作

# Define ANDROID_HOME, if not defined already
export ANDROID_HOME="~/Library/Android/sdk"

# Create the folder if missing
mkdir -p $ANDROID_HOME

# Let the tool know that it should use that SDK location. 
sdkmanager --list --sdk_root=$ANDROID_HOME

——sdk_root选项的文档说“使用指定的SDK根而不是包含此工具的SDK”。这让我想到,尽管该工具是独立发布的,但它有望成为SDK安装包的一部分。

其他回答

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

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

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"

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

使用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