如何通过 CLI 在 macOS 上安装 Android 模拟器?

问题描述 投票:0回答:1

我正在尝试在 macOS 12 上通过 CLI 安装 Android 模拟器工具。

所以首先我安装了

openjdk

$ brew install openjdk
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/22.0.2
####################################################################################################################################################################################### 100.0%
==> Fetching openjdk
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:84795b272691e9ee02b9a0bb9fba35552c1ae8d3b977be2468dc71e57aa4e42f
Already downloaded: /Users/sebastien/Library/Caches/Homebrew/downloads/d77dda9a4f3951018aa3f9bb83beae31f635ebac5ba939d25d7278da1345ca95--openjdk--22.0.2.monterey.bottle.tar.gz
==> Pouring openjdk--22.0.2.monterey.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.profile

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"
==> Summary
🍺  /usr/local/Cellar/openjdk/22.0.2: 602 files, 330MB
Warning: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK is set: not checking for outdated
dependents or dependents with broken linkage!

然后我将openjdk添加到路径中:

$ which java
/usr/local/opt/openjdk/bin/java
$ 

终于,我安装了

android-commandlinetools

$ brew install android-commandlinetools
==> Caveats
Default Android SDK root is /usr/local/share/android-commandlinetools

android-commandlinetools requires Java. You can install the latest version with:
  brew install --cask temurin

==> Downloading https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip
##################################################################################################################################### 100.0%
==> Installing Cask android-commandlinetools
==> Moving Generic Artifact 'cmdline-tools' to '/usr/local/share/android-commandlinetools/cmdline-tools/latest'
==> Linking Binary 'avdmanager' to '/usr/local/bin/avdmanager'
==> Linking Binary 'lint' to '/usr/local/bin/lint'
==> Linking Binary 'retrace' to '/usr/local/bin/retrace'
==> Linking Binary 'sdkmanager' to '/usr/local/bin/sdkmanager'
==> Linking Binary 'apkanalyzer' to '/usr/local/bin/apkanalyzer'
==> Linking Binary 'screenshot2' to '/usr/local/bin/screenshot2'
🍺  android-commandlinetools was successfully installed!
Warning: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK is set: not checking for outdated
dependents or dependents with broken linkage!

我期待

emulator
工具,但我在下面看不到
emulator
工具:

$ brew info android-commandlinetools | grep bin/
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/avdmanager (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/lint (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/retrace (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/sdkmanager (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/apkanalyzer (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/screenshot2 (Binary)
$ 

EDIT0 :感谢@gtxtreme,我终于成功地使用这些命令安装了 Android

emulator
工具:

$ sdkmanager --list | grep emulator
  emulator | 34.2.16 | Android Emulator | emulator
  emulator                                                                                 | 34.2.16           | Android Emulator
$ yes | sdkmanager --licenses > /dev/null
$ sdkmanager --install emulator
[=======================================] 100% Unzipping... emulator/._NOTICE.tx

$ which emulator
$ export ANDROID_SDK_ROOT=/usr/local/share/android-commandlinetools
$ PATH="$ANDROID_SDK_ROOT/emulator:$PATH"
$ which emulator
/usr/local/share/android-commandlinetools/emulator/emulator
$ 
android macos command-line-interface homebrew emulation
1个回答
1
投票

您可以使用已有的

sdkmanager
命令安装模拟器

  1. 对于具有默认 api(没有 google api)的通用皮肤模拟器,可与 CI 上的 Intel Macbook 一起使用(也可以使用 google_atd):

  2. 列出所有可供下载的系统映像:

sdkmanager --list | grep system-images

下载图片:

sdkmanager --install "system-images;android-30;aosp_atd;x86"

创建模拟器:

echo "no" | avdmanager --verbose create avd --force --name "generic_api30_aosp_atd_emulator" --package "system-images;android-30;aosp_atd;x86" --tag "aosp_atd" --abi "x86"

然后您可以使用 CLI 文档启动模拟器,可以在此处

找到该文档

您可以在此处查看安装新模拟器的命令。上面的命令取自这个要点

© www.soinside.com 2019 - 2024. All rights reserved.