简体   繁体   English

Android SDK工具+ Flutter:正确的目录结构和环境变量

[英]Android SDK tools + Flutter: correct directory structure and environment variables

I am having the damnedest time getting Flutter to find the SDK command-line tools .我有最该死的时间让Flutter找到SDK 命令行工具 I am trying to install the latter by downloading the zip provided at that link and unpacking it in say ${HOME}/Android .我正在尝试通过下载该链接提供的 zip 并将其解压缩到${HOME}/Android中来安装后者。 This produces a tools directory, and if I run the executable这会产生一个tools目录,如果我运行可执行文件

${HOME}/Android/tools/bin/sdkmanager

directly (whith any number of options, etc.) I always get an error as documented in this other post .直接(带有任意数量的选项等)我总是得到一个错误,如一篇文章中所述。 The solution recommended there actually works: move the tools directory further down the tree to get the path那里推荐的解决方案实际上有效:将tools目录移到树的下方以获取路径

${HOME}/Android/cmdline-tools/tools/bin/sdkmanager

That new intermediate directory must be named cmdline-tools though;不过,新的中间目录必须命名为cmdline-tools I've tried other things ( Sdk , sdk_manager , etc.) to no effect: the same errors occur.我尝试了其他方法( Sdksdk_manager等)无效:发生相同的错误。


Now, poking around in the cloned Flutter repo , I see in the file dev/bots/download_android_sdk.sh that I'm supposed to have the executable现在,在克隆的Flutter repo中四处寻找,我在文件dev/bots/download_android_sdk.sh中看到我应该有可执行文件

$ANDROID_SDK_ROOT/tools/bin/sdkmanager

This tips me off that in my setup I need这提示我在我的设置中我需要

ANDROID_SDK_ROOT=${HOME}/Android/cmdline-tools

exporting that and running a bunch of sdkmanager installation commands (like say导出它并运行一堆sdkmanager安装命令(比如说

$ANDROID_SDK_ROOT/tools/bin/sdkmanager platform-tools

and the like) I see that my ${HOME}/Android directory is starting to get populated with the corresponding directories platform-tools , build-tools , etc. So those newly-installed directories live at the same level as my $ANDROID_SDK_ROOT which remember, as I'm doing this, is set to $HOME/Android/cmdline-tools .等等)我看到我的${HOME}/Android目录开始填充相应的目录platform-toolsbuild-tools等。所以这些新安装的目录与我的$ANDROID_SDK_ROOT处于同一级别请记住,当我这样做时,设置为$HOME/Android/cmdline-tools

On the other hand though, when I then go look (in the same Flutter repo) in the file另一方面,当我在文件中查看 go 时(在同一个 Flutter 存储库中)

packages/flutter_tools/lib/src/android/android_sdk.dart

I see that I'm supposed to have the directory $ANDROID_SDK_ROOT/build-tools .我看到我应该有目录$ANDROID_SDK_ROOT/build-tools This is in direct contradiction with the previous observation that build-tools and the like are supposed to be at the same level as $ANDROID_SDK_ROOT , and not under it.这与之前的观察直接矛盾,即build-tools等应该与$ANDROID_SDK_ROOT处于同一级别,而不是它之下。

My problem is I don't know how to square this apparent self-contradiction in the Flutter codebase.我的问题是我不知道如何在 Flutter 代码库中解决这种明显的自相矛盾。 Which is it?它是哪一个? In my setup, is ANDROID_SDK_ROOT supposed to be $HOME/Android or $HOME/Android/cmdline-tools ?在我的设置中, ANDROID_SDK_ROOT应该是$HOME/Android还是$HOME/Android/cmdline-tools


PS附言

I understand that $ANDROID_SDK_ROOT is supposed to be "the SDK installation directory", but in this context this tells me nothing: after all, installing SDK is precisely what I'm trying to do.知道$ANDROID_SDK_ROOT应该是“SDK 安装目录”,但在这种情况下,这并没有告诉我:毕竟,安装SDK正是我想要做的。

You got a couple comments on GitHub as well, but just be aware that the files in the dev/ folder in the Flutter repository are mainly intended for CI purposes and for people who are developing the Flutter framework itself.您也收到了关于 GitHub 的一些评论,但请注意,Flutter 存储库中dev/文件夹中的文件主要用于 CI 目的以及开发 Flutter 框架本身的人。

The scripts you're pointing out are actually stale files that used to help set up some tests we ran on CI.您指出的脚本实际上是用于帮助设置我们在 CI 上运行的一些测试的陈旧文件。 We now set those tests up differently, but forgot to delete the files - so thanks for pointing this out, they're soon to be gone!我们现在以不同的方式设置这些测试,但忘记删除文件 - 所以感谢您指出这一点,它们很快就会消失!

The best way to set up your Android SDK is by following the instructions at the Android Studio site.设置 Android SDK 的最佳方法是按照 Android Studio 站点上的说明进行操作。 You can either use Studio to do it, or just download the SDK bundle(s) themselves.您可以使用 Studio 来完成,也可以自己下载 SDK 包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM