Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/build_script #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 2 additions & 41 deletions scripts/android/before_plugin_install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var fs = require('fs');
var projectBuilderJsPath = "platforms/android/cordova/lib/builders/ProjectBuilder.js"
var projectBuilderJsPath = "node_modules/cordova-android/lib/builders/ProjectBuilder.js"
var gradleProperties = "platforms/android/gradle.properties";
var buildGradleFilePath = "platforms/android/build.gradle";
/**
Expand Down Expand Up @@ -54,44 +54,6 @@ function writeImplementationToBuilderJsFile() {
}



/**
* 更新 gradle
*/
function updateFlutterGradleToBuilderJsFile() {
//先匹配到文本
var data = readProjectBuilderJsFile();
var txt = null;
var result = data.match(/var.*?\-all\.zip';/);
if (result != null && result.length > 0) {
txt = result[0];
} else {
txt = data.match(/const.*?\-all\.zip';/)[0];
}

if (txt != null) {
txt = txt.replace("const ", "var ");
data = data.replace(txt, `
${txt};
//#CORDOVA-PLUGIN-FLUTTER#START
distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\\\://services.gradle.org/distributions/gradle-5.6.4-all.zip';
//#CORDOVA-PLUGIN-FLUTTER#END
`);
writeProjectBuilderJsFile(data);
}
}
function updateToGradlePropertiesJsFile() {
var data = fs.readFileSync(gradleProperties, 'utf8');
data += `

#CORDOVA-PLUGIN-FLUTTER#START
android.useAndroidX=true
android.enableJetifier=true
#CORDOVA-PLUGIN-FLUTTER#END
`;
fs.writeFileSync(gradleProperties, data);
}

function updateToBuildGradle() {
var data = fs.readFileSync(buildGradleFilePath, 'utf8');
data = data.replace(
Expand All @@ -112,10 +74,9 @@ function updateToBuildGradle() {
console.log("*** 注入 platforms/android/cordova/lib/builders/ProjectBuilder.js 与flutter相关的脚本 ***");
writeFlutterSettingsGradleToBuilderJsFile();
writeImplementationToBuilderJsFile();
updateFlutterGradleToBuilderJsFile();

// console.log("*** 注入 platforms/android/gradle.properties 与flutter相关的设置 ***");
// updateToGradlePropertiesJsFile();


console.log("*** 注入 platforms/android/build.gradle 与flutter相关的设置 ***");
updateToBuildGradle();
Expand Down
2 changes: 1 addition & 1 deletion scripts/android/before_plugin_uninstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require('fs');
var projectBuilderJsPath = "platforms/android/cordova/lib/builders/ProjectBuilder.js"
var projectBuilderJsPath = "node_modules/cordova-android/lib/builders/ProjectBuilder.js"
var gradleProperties = "platforms/android/gradle.properties";

function removeFromGradlePropertiesJsFile() {
Expand Down
40 changes: 20 additions & 20 deletions scripts/before_plugin_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ function checkRequireEnvironment(callback) {
process.exec('cordova platform',
function (error, stdout, stderr) {
console.log(stdout);
try {
var androidVersion = /android \d\.\d\.\d/.exec(stdout)[0];
if (parseInt(androidVersion.replace("android ", "").sub(0, 1)) < 9) {
console.error("\033[31m 不支持低于10.0.0版本的cordova-android \033[0m");
}
} catch (error) {
console.error("***\033[31m 检测必须的环境失败,cordova-android没有安装,请使用命令cordova platform add android安装 *** \033[0m");
// try {
// var androidVersion = /android \d\.\d\.\d/.exec(stdout)[0];
// if (parseInt(androidVersion.replace("android ", "").sub(0, 1)) < 9) {
// console.error("\033[31m 不支持低于10.0.0版本的cordova-android \033[0m");
// }
// } catch (error) {
// console.error("***\033[31m 检测必须的环境失败,cordova-android没有安装,请使用命令cordova platform add android安装 *** \033[0m");

}
// }

try {
var iosVersion = /ios \d\.\d\.\d/.exec(stdout)[0];
if (parseInt(iosVersion.replace("ios ", "").sub(0, 1)) < 5) {
console.error("\033[31m 不支持低于5.1.1版本的cordova-ios \033[0m");
}
} catch (error) {
console.error("***\033[31m 检测必须的环境失败,cordova-ios没有安装,请使用命令cordova platform add ios安装 *** \033[0m");
}
if (error !== null) {
console.log('exec error: ' + error);
}
// try {
// var iosVersion = /ios \d\.\d\.\d/.exec(stdout)[0];
// if (parseInt(iosVersion.replace("ios ", "").sub(0, 1)) < 5) {
// console.error("\033[31m 不支持低于5.1.1版本的cordova-ios \033[0m");
// }
// } catch (error) {
// console.error("***\033[31m 检测必须的环境失败,cordova-ios没有安装,请使用命令cordova platform add ios安装 *** \033[0m");
// }
// if (error !== null) {
// console.log('exec error: ' + error);
// }
next2();
}
);
Expand Down Expand Up @@ -119,7 +119,7 @@ function checkRequireEnvironment(callback) {


}
console.log("\033[33m *** 检测必需的环境 ***\033[0m");
console.log("\033[33m *** Detect required environment ***\033[0m");
checkRequireEnvironment(function () {
installFlutterModule();
});