From bf18a2e41f1ac6a5481c4d3af1c5b388220cdc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Neves?= Date: Wed, 22 Feb 2023 11:11:06 -0300 Subject: [PATCH] fix: install scripts --- scripts/android/before_plugin_install.js | 43 +--------------------- scripts/android/before_plugin_uninstall.js | 2 +- scripts/before_plugin_install.js | 40 ++++++++++---------- 3 files changed, 23 insertions(+), 62 deletions(-) diff --git a/scripts/android/before_plugin_install.js b/scripts/android/before_plugin_install.js index 8a928eb..7ec74a9 100644 --- a/scripts/android/before_plugin_install.js +++ b/scripts/android/before_plugin_install.js @@ -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"; /** @@ -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( @@ -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(); diff --git a/scripts/android/before_plugin_uninstall.js b/scripts/android/before_plugin_uninstall.js index ef9c0af..c9f91c9 100644 --- a/scripts/android/before_plugin_uninstall.js +++ b/scripts/android/before_plugin_uninstall.js @@ -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() { diff --git a/scripts/before_plugin_install.js b/scripts/before_plugin_install.js index a8b563f..0ff7430 100644 --- a/scripts/before_plugin_install.js +++ b/scripts/before_plugin_install.js @@ -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(); } ); @@ -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(); });