当我尝试运行我的 flutter 项目时遇到此错误:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDevAndroidDebugJavaWithJavac'.
> Failed to install the following SDK components:
platforms;android-34 Android SDK Platform 34
build-tools;30.0.3 Android SDK Build-Tools 30.0.3
The SDK directory is not writable (/opt/android-sdk)
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Error: Gradle task assembleDevAndroidDebug failed with exit code 1
我的操作系统是 arch (顺便说一句),我已经运行了
是的 | sdkmanager --许可证
和
flutter doctor --android-licenses
这是运行 flutter doctor 的输出:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on Arch Linux 6.9.9-arch1-1, locale pt_BR.UTF-8)
[!] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/to/linux-android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
✗ No valid Android SDK platforms found in /opt/android-sdk/platforms. Directory was empty.
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (2 available)
[✓] Network resources
! Doctor found issues in 3 categories.
我不知道为什么它不能将
/opt/android-sdk
识别为sdk文件夹。
另外,如果这有助于解决问题,我的 .zshrc 文件中有以下导出:
export ANDROID_HOME=/opt/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin/:$PATH
看来您需要将“/sdk”附加到导出行的末尾,然后如果
source .bash_profile
中有一个名为“sdk”的子目录,则执行命令/opt/android-sdk/
。
export ANDROID_HOME=/opt/android-sdk/sdk
建议您安装Android Studio,为必要的Android运行环境做准备。