【发布时间】:2018-03-26 11:24:35
【问题描述】:
我在尝试cordova run android 命令时一直出现Failed to find target with hash string 'android-26' 错误。
虽然我的 Android > 平台文件夹 (see image) 中有一个“android-26”文件夹。我看到了很多问题,但我仍然没有找到适合我的解决方案。 我已经安装了 Build-tools 和 API 26(参见the Android SDK Manager、Android SDK Manager in Android Studio 的图片)
这是我尝试使用 Cordova 构建的第一个应用程序。
这是完整的跟踪:
Android Studio project detected
ANDROID_HOME=D:\Programmes\AndroidStudio
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
studio
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon, 2 incompatible and 3 stopped Daemons could not be reused, use --status for details
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Checking the license for package Android SDK Build-Tools 27.0.3 in D:\Programmes\AndroidStudio\licenses
License for package Android SDK Build-Tools 27.0.3 accepted.
Preparing "Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)".
"Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)" ready.
Installing Android SDK Build-Tools 27.0.3 in D:\Programmes\AndroidStudio\build-tools\27.0.3
"Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)" complete.
"Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)" finished.
Checking the license for package Android SDK Platform 26 in D:\Programmes\AndroidStudio\licenses
License for package Android SDK Platform 26 accepted.
Preparing "Install Android SDK Platform 26 (revision: 2)".
"Install Android SDK Platform 26 (revision: 2)" ready.
Installing Android SDK Platform 26 in D:\Programmes\AndroidStudio\platforms\android-26
"Install Android SDK Platform 26 (revision: 2)" complete.
"Install Android SDK Platform 26 (revision: 2)" finished.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':CordovaLib'.
Failed to find target with hash string 'android-26' in: D:\Programmes\AndroidStudio
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 7m 14s
(node:8356) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':CordovaLib'.
Failed to find target with hash string 'android-26' in: D:\Programmes\AndroidStudio
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 7m 14s
【问题讨论】:
-
感谢您的回答!但正如您在 Android SDK 管理器的图像中看到的那样,android-26 似乎已正确安装。当我使用 Cordova 时,我没有帖子中提到的相同的“build.gradle”文件。我在 android 文件夹中有一个“build.gradle”文件,将
defaultTargetSdkVersion和defaultCompileSdkVersion设置为 26。