你應該參考doFindLatestInstalledBuildTools
方法cordova.gradle文件:
String doFindLatestInstalledBuildTools(String minBuildToolsVersion) {
def availableBuildToolsVersions
try {
availableBuildToolsVersions = getAvailableBuildTools()
} catch (e) {
println "An exception occurred while trying to find the Android build tools."
throw e
}
if (availableBuildToolsVersions.length > 0) {
def highestBuildToolsVersion = availableBuildToolsVersions[0]
if (compareVersions(highestBuildToolsVersion, minBuildToolsVersion) < 0) {
throw new RuntimeException(
"No usable Android build tools found. Highest installed version is " +
highestBuildToolsVersion + "; minimum version required is " +
minBuildToolsVersion + ".")
}
highestBuildToolsVersion
} else {
throw new RuntimeException(
"No installed build tools found. Install the Android build tools version " +
minBuildToolsVersion + " or higher.")
}
}
Obviosly,getAvailableBuildTools()
返回空數組:
String[] getAvailableBuildTools() {
def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
buildToolsDir.list()
.findAll { it ==~ /[0-9.]+/ }
.sort { a, b -> compareVersions(b, a) }
}
在我的情況下,System.getenv("ANDROID_HOME")
返回錯誤的路徑getAndroidSdkDir()
方法,所以解決方案是:
- 只要你真正的Android SDK路徑替換
System.getenv("ANDROID_HOME")
(但是你應該記住,SDK的位置不同,在其他PC)
- 設置正確的路徑
$ANDROID_HOME
環境變量
可以在build.gradle
文件手動設置構建工具版本,並跳過調用上述方法(一定要設置爲它在應用中的所有模塊):
機器人{ buildToolsVersion 「your_version_here」 }
謝謝親愛的爲我工作.... – vinod
該文件在哪裏? –