cordova build时出错Minimum supported Gradle version is 5.4.1. Current version is 4.10.3
cordova build项目时,出现错误:/home/kyun/Desktop/Cordova/sample/platforms/android/gradlew: Command failed with exit code 1 Error output:FAILURE: Build failed with an exception.* Where:Build file '/home/k...
·
cordova build项目时,出现错误:
/home/kyun/Desktop/Cordova/sample/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/kyun/Desktop/Cordova/sample/platforms/android/app/build.gradle' line: 20
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Minimum supported Gradle version is 5.4.1. Current version is 4.10.3. If using the gradle wrapper, try editing the distributionUrl in /home/kyun/Desktop/Cordova/sample/gradle/wrapper/gradle-wrapper.properties to gradle-5.4.1-all.zip
我的android studio更新了Gradle的版本,再终端执行cordova build时就报了上面的错误。其实,我们要找到Cordova项目是如何指定它的gradle版本的,这样就可以正确修改了。
解决办法:
Cordova项目的gradle版本是在如下这份文件里指定的:
/home/kyun/Desktop/Cordova/sample/platforms/android/cordova/lib/builders/ProjectBuilder.js,我们可以从下面看到它指定的gradle版本:
// If the gradle distribution URL is set, make sure it points to version we want.
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
// For some reason, using ^ and $ don't work. This does the job, though.
var distributionUrlRegex = /distributionUrl.*zip/;
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.10.3-all.zip';
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
所以只需要将上面的4.10.3改成5.4.1,恰好就是我更新Android Studio的gradle版本后,在本地最新的版本。调整后,再cordova build项目就OK了。
谢谢阅读。
更多推荐


所有评论(0)