模拟器无法使用通过 MacOS 上的 brew 安装的 android-commandlinetools 工作(找不到有效的 SDK 根路径)

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

我在尝试运行我的 Android 模拟器和 SDK 时遇到了一些麻烦,

首先,当我尝试运行时,SDK 似乎已被弃用:

brew install --cask android-sdk

我收到此错误:

android-sdk 已正式停止上游。

检查这里我得到这篇文章

所以我尝试安装命令行工具:

brew install --cask android-commandlinetools

此命令的输出如下:

 Downloading https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip
Already downloaded: /Users/testcomputer/Library/Caches/Homebrew/downloads/76a8eee9e0f62a261183b58c78c572e87fbd8acad42af527407b2974526cb4de--commandlinetools-mac-11076708_latest.zip
==> 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'

我导出了 zshrc 文件中的变量:

export ANDROID_SDK_ROOT=/usr/local/share/android-commandlinetools
export PATH=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$PATH

我还安装了模拟器:

sdkmanager "emulator"

此后我尝试获取 Android 图像:

sdkmanager "system-images;android-34;google_apis;x86_64"

这工作正常...

并创建avd:

avdmanager create avd -n myavd -k "system-images;android-34;google_apis;x86_64" --device "pixel_3"

到目前为止一切顺利,现在我进入了我的模拟器路径:

cd $ANDROID_SDK_ROOT
ls //=> output cmdline-tools    emulator    licenses    platform-tools  system-images
cd emulator
ls //=> LICENSE         android-info.txt    emulator        lib64            
package.xml     resources
NOTICE.csv      bin64           emulator-check      mksdcard        qemu             
source.properties
NOTICE.txt      crashpad_handler    include         netsimd         qemu-img
_CodeSignature      crashreport     lib         nimble_bridge       qsn

现在我尝试运行我的模拟器:

./emulator -avd myavd

我得到的错误是这样的:

INFO    | Storing crashdata in: /tmp/android-testcomputer/emu-crash-35.1.20.db, detection is enabled for process: 68485
INFO    | Android emulator version 35.1.20.0 (build_id 12234392) (CL:N/A)
INFO    | Graphics backend: gfxstream
INFO    | checking ANDROID_HOME for valid sdk root.
emulator: WARN: /Users/testcomputer/Library/Android/sdk is not a directory, and canot be sdk root
INFO    | checking ANDROID_SDK_ROOT for valid sdk root.
WARNING | platforms subdirectory is missing under /usr/local/share/android-commandlinetools, please install it
emulator: WARN: Cannot find valid sdk root from environment variable ANDROID_HOME nor ANDROID_SDK_ROOT,Try to infer from emulator's path
INFO    | guessed sdk root is /usr/local/share/android-commandlinetools
WARNING | platforms subdirectory is missing under /usr/local/share/android-commandlinetools, please install it
INFO    | guessed sdk root /usr/local/share/android-commandlinetools does not seem to be valid
INFO    | guessed sdk root is /usr/local/share
WARNING | platforms subdirectory is missing under /usr/local/share, please install it
INFO    | guessed sdk root /usr/local/share does not seem to be valid
INFO    | guessed sdk root is /usr/local
WARNING | platforms subdirectory is missing under /usr/local, please install it
INFO    | guessed sdk root /usr/local does not seem to be valid
WARNING | invalid sdk root /usr/local
emulator: WARN: Cannot find valid sdk root path.
PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value [/usr/local/share/android-commandlinetools]!

我需要安装其他东西吗?...不知道为什么在使用 android-commandlinetools 时尝试访问 SDK 文件夹,我没有 SDK 文件夹

希望你们能帮助我,我是android开发的新手。谢谢!

android sdk android-emulator android-sdk-manager
1个回答
0
投票

ChatGPT 在这里帮了我很多,我缺少平台目录

sdkmanager“平台;android-XX”“平台工具”“模拟器”“系统映像;android-XX;默认;x86_64”

其中 XX 是 Android 版本 这将安装所有必需的组件

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