未能找到具有哈希字符串 'android-25' 的目标,但实际安装了 android-25
Failed to find target with hash string 'android-25', though android-25 is actually installed
我在 OpenStack 中有一个 Ubuntu Xenial VM 运行,我在那里下载了最新的 Android SDK 工具(tools_r25.2.3-linux.zip ) from https://developer.android.com/studio/index.html.一切都配置好了:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ANDROID_HOME=<ANDROID_SDK_PATH>
PATH=${PATH}:${ANDROID_HOME}
echo "sdk.dir=<ANDROID_SDK_PATH>" > <MY_ANDROID_PROJECT_PATH>/local.properties
但是当尝试执行任务时:./gradlew clean
,出现错误:
Preparing "Install Android SDK Build-Tools 25".
Warning: Trying to install into ${ANDROID_HOME}/build-tools/25.0.0/ but package "Android SDK Tools 25.2.4" already exists at ${ANDROID_HOME}. It must be deleted or moved away before installing into a child directory.
Preparing "Install Android SDK Platform 25".
Warning: Trying to install into ${ANDROID_HOME}/platforms/android-25/ but package "Android SDK Tools 25.2.4" already exists at ${ANDROID_HOME}. It must be deleted or moved away before installing into a child directory.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':demo'.
> Failed to install the following SDK components:
[Android SDK Build-Tools 25, Android SDK Platform 25]
Please install the missing components using the SDK manager in Android Studio.
实际上正如错误日志中提到的那样,我已经安装了所需的工具。 运行 $ANDROID_HOME/bin/sdkmanager --list
显示我安装的包:
Installed packages:
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;25.0.0 | 25.0.0 | Android SDK Build-Tools 25 | build-tools/25.0.0/
extras;android;m2repository | 41.0.0 | Android Support Repository, re... | extras/android/m2repository/
platform-tools | 25.0.2 | Android SDK Platform-Tools 25.0.2 | platform-tools/
platforms;android-25 | 3 | Android SDK Platform 25, rev 3 | platforms/android-25/
tools | 25.2.4 | Android SDK Tools 25.2.4 | tools/
这里可能有什么问题?我对这里的SDK路径有点怀疑。
刚刚证实了我的推测 - 这是由于最新的 Android SDK 版本中的新变化所致。
感谢上帝,我们有时光机,这样我们就可以回去看看到底发生了什么(无法从 SDK Tools Release Notes 中找到任何线索)。
- SDK download page on 2016.12.06 和 SDK 文件:
android-sdk_r24.4.1-linux.tgz
- SDK download page on 2016.12.09 and the SDK file: tools_r25.2.3-linux.zip
我们来看看ANDROID_HOME
改变前后的文件结构
之前:
android-sdk-linux
├── SDK Readme.txt
├── add-ons (empty)
├── platforms (empty)
└── tools
├── a bunch of preloaded tools
├── ...
└── ...
之后:
tools
├── a bunch of preloaded tools
├── ...
└── ...
不再有 add-ons
或 platforms
,只有 tools
作为新的根目录。
问题:如果直接将$ANDROID_HOME
设置到解压后的最顶层tools
目录,Gradle会混淆。
解决方法:解压新的SDK文件后(会得到一个tools
目录),新建一个目录(如android-sdk
),然后将 tools
目录完全移动到空的 android-sdk
中,然后将环境变量设置为:
ANDROID_HOME=/android-sdk
PATH=${PATH}:${ANDROID_HOME}/tools
简而言之:不要 将 $ANDROID_HOME
直接设置到新的 tools
父目录,将其包裹在另一个父目录中!
我刚刚在我的 android 工作室中使用了 Invalidate catches / Restart。它对我有用。
我在 OpenStack 中有一个 Ubuntu Xenial VM 运行,我在那里下载了最新的 Android SDK 工具(tools_r25.2.3-linux.zip ) from https://developer.android.com/studio/index.html.一切都配置好了:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ANDROID_HOME=<ANDROID_SDK_PATH>
PATH=${PATH}:${ANDROID_HOME}
echo "sdk.dir=<ANDROID_SDK_PATH>" > <MY_ANDROID_PROJECT_PATH>/local.properties
但是当尝试执行任务时:./gradlew clean
,出现错误:
Preparing "Install Android SDK Build-Tools 25".
Warning: Trying to install into ${ANDROID_HOME}/build-tools/25.0.0/ but package "Android SDK Tools 25.2.4" already exists at ${ANDROID_HOME}. It must be deleted or moved away before installing into a child directory.
Preparing "Install Android SDK Platform 25".
Warning: Trying to install into ${ANDROID_HOME}/platforms/android-25/ but package "Android SDK Tools 25.2.4" already exists at ${ANDROID_HOME}. It must be deleted or moved away before installing into a child directory.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':demo'.
> Failed to install the following SDK components:
[Android SDK Build-Tools 25, Android SDK Platform 25]
Please install the missing components using the SDK manager in Android Studio.
实际上正如错误日志中提到的那样,我已经安装了所需的工具。 运行 $ANDROID_HOME/bin/sdkmanager --list
显示我安装的包:
Installed packages:
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;25.0.0 | 25.0.0 | Android SDK Build-Tools 25 | build-tools/25.0.0/
extras;android;m2repository | 41.0.0 | Android Support Repository, re... | extras/android/m2repository/
platform-tools | 25.0.2 | Android SDK Platform-Tools 25.0.2 | platform-tools/
platforms;android-25 | 3 | Android SDK Platform 25, rev 3 | platforms/android-25/
tools | 25.2.4 | Android SDK Tools 25.2.4 | tools/
这里可能有什么问题?我对这里的SDK路径有点怀疑。
刚刚证实了我的推测 - 这是由于最新的 Android SDK 版本中的新变化所致。
感谢上帝,我们有时光机,这样我们就可以回去看看到底发生了什么(无法从 SDK Tools Release Notes 中找到任何线索)。
- SDK download page on 2016.12.06 和 SDK 文件: android-sdk_r24.4.1-linux.tgz
- SDK download page on 2016.12.09 and the SDK file: tools_r25.2.3-linux.zip
我们来看看ANDROID_HOME
改变前后的文件结构
之前:
android-sdk-linux
├── SDK Readme.txt
├── add-ons (empty)
├── platforms (empty)
└── tools
├── a bunch of preloaded tools
├── ...
└── ...
之后:
tools
├── a bunch of preloaded tools
├── ...
└── ...
不再有 add-ons
或 platforms
,只有 tools
作为新的根目录。
问题:如果直接将$ANDROID_HOME
设置到解压后的最顶层tools
目录,Gradle会混淆。
解决方法:解压新的SDK文件后(会得到一个tools
目录),新建一个目录(如android-sdk
),然后将 tools
目录完全移动到空的 android-sdk
中,然后将环境变量设置为:
ANDROID_HOME=/android-sdk
PATH=${PATH}:${ANDROID_HOME}/tools
简而言之:不要 将 $ANDROID_HOME
直接设置到新的 tools
父目录,将其包裹在另一个父目录中!
我刚刚在我的 android 工作室中使用了 Invalidate catches / Restart。它对我有用。