使用ionic编译项目时 有的项目会提示
Minimum supported Gradle version is 6.1.1. Current version is 4.10.3. If using the gradle wrapper, try editing the distributionUrl in /Users/jason/develop/industics/ibrain-app/in-mom-pda/gradle/wrapper/gradle-wrapper.properties to gradle-6.1.1-all.zip
为什么自己明明安装了5.6.3 还是报4.10.3这个错呢.
一直没搞清楚原因, 今天感觉搞不下去了.
就在项目里搜索了4.10.3
在node_moules的ProjectBuilder.js中 发现如下代码
prepEnv (opts) {
var self = this;
return check_reqs.check_gradle()
.then(function (gradlePath) {
return self.runGradleWrapper(gradlePath);
}).then(function () {
return self.prepBuildFiles();
}).then(function () {
// 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');
shell.chmod('u+w', gradleWrapperPropertiesPath);
shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
var propertiesFilePath = path.join(self.root, propertiesFile);
if (opts.packageInfo) {
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
} else if (isAutoGenerated(propertiesFilePath)) {
shell.rm('-f', propertiesFilePath);
}
});
}
其中又一行代码
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.10.3-all.zip';
感觉问题就处在这.
感觉应该要将其设置为环境变量.可是要设置什么值呢?
上网搜索下CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL" 果然在 https://www.jianshu.com/p/7a465d169486 找到了答案
在~/.bash_profile 或者 ~/.zshrc [如果使用ohmyzsh的话]
export GRADLE_HOME=$HOME/apps/gradle-5.6.4
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=file://$GRADLE_HOME
export PATH=$GRADLE_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH
注意 GRADLE_HOME 是/开头的 所以这里要加上file://