From 06367eb5abc9b6cf3eab21c1de2b6455fc5ed5ea Mon Sep 17 00:00:00 2001 From: swayangjit Date: Wed, 8 May 2024 13:31:16 +0530 Subject: [PATCH 1/2] Issue #DJP-000 chore: Updated scripts --- android/app/build.gradle | 26 ++++----- hooks/copyGradleProperties.js | 58 +++---------------- hooks/updateManifest.js | 102 ---------------------------------- package.json | 1 - 4 files changed, 20 insertions(+), 167 deletions(-) delete mode 100644 hooks/updateManifest.js diff --git a/android/app/build.gradle b/android/app/build.gradle index c061682..d902f8b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -19,20 +19,20 @@ android { } } signingConfigs { - release { - storeFile = file("keystore/android_keystore.jks") - storePassword System.getenv("SIGNING_STORE_PASSWORD") - keyAlias System.getenv("SIGNING_KEY_ALIAS") - keyPassword System.getenv("SIGNING_KEY_PASSWORD") - } - } - buildTypes { - release { -signingConfig signingConfigs.release - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } + release { + storeFile = file("keystore/android_keystore.jks") + storePassword System.getenv("SIGNING_STORE_PASSWORD") + keyAlias System.getenv("SIGNING_KEY_ALIAS") + keyPassword System.getenv("SIGNING_KEY_PASSWORD") + } +} +buildTypes { + release { + signingConfig signingConfigs.release + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + } } repositories { diff --git a/hooks/copyGradleProperties.js b/hooks/copyGradleProperties.js index 9360b7b..9ad5c0c 100644 --- a/hooks/copyGradleProperties.js +++ b/hooks/copyGradleProperties.js @@ -10,10 +10,6 @@ const appid = properties['app_id']; const verCode = properties['app_version_code']; console.log("****** gradle properties ", properties); -let appId = `applicationId "${appid}"`; -let appendStr = '\t\tapplicationId app_id \n' + - '\t\tresValue("string", "app_name", "${app_name}") \n' + - '\t\tresValue("string", "app_id", "${app_id}")' let androidbuild = "android/app/build.gradle"; let appendStrCode = `\t\tversionCode ${verCode}` @@ -23,7 +19,7 @@ fs.readFile("android/gradle.properties", "utf-8", (err, data) => { console.error(err); return; } - if(data.match("# config.properties")) { + if (data.match("# config.properties")) { console.log("exist "); } else { fs.readFile("configuration/config.properties", 'utf8', (err, data) => { @@ -36,44 +32,21 @@ fs.readFile("android/gradle.properties", "utf-8", (err, data) => { } }) - // build gardle fix +// build gardle fix fs.readFile(androidbuild, 'utf8', (err, data) => { if (err) { console.error(err); return; } let arr = data.split('\n'); - let exists = false; - arr.forEach((a, i)=> { - if(a.match(appId)) { - arr[i] = appendStr - } - if(a.match('versionCode') && !a.match(appendStrCode)) { + arr.forEach((a, i) => { + if (a.match('versionCode') && !a.match(appendStrCode)) { arr[i] = appendStrCode } - if(a.match("signingConfigs {")) { - exists = true; - } - if(a.match("minifyEnabled false")) { - arr[i] = - `signingConfig signingConfigs.release - minifyEnabled true` - } - if(a.match('buildTypes {') && !exists) { - arr[i] = `signingConfigs { - release { - storeFile = file("keystore/android_keystore.jks") - storePassword System.getenv("SIGNING_STORE_PASSWORD") - keyAlias System.getenv("SIGNING_KEY_ALIAS") - keyPassword System.getenv("SIGNING_KEY_PASSWORD") - } - } - buildTypes {` - } }) fs.writeFile(androidbuild, arr.join("\n"), (err) => { if (err) { - console.error("********* err", err); + console.error("********* err", err); } }); }); @@ -81,7 +54,7 @@ fs.readFile(androidbuild, 'utf8', (err, data) => { function readPropertiesFile(filePath) { const content = fs.readFileSync(filePath, 'utf-8'); const lines = content.split('\n'); - + const properties = {}; for (const line of lines) { @@ -95,21 +68,4 @@ function readPropertiesFile(filePath) { } return properties; -} - -fs.readFile("android/variables.gradle", 'utf-8', (err, data) => { - if (err) { - console.error(err); - return; - } - if(data.match("minSdkVersion = 22")) { - console.log("exist "); - let updatedData = data.replace('minSdkVersion = 22', 'minSdkVersion = 23') - fs.writeFile("android/variables.gradle", updatedData, (err) => { - if (err) { - console.error("********* err", err); - } - }); - } - -}) \ No newline at end of file +} \ No newline at end of file diff --git a/hooks/updateManifest.js b/hooks/updateManifest.js deleted file mode 100644 index 7766e91..0000000 --- a/hooks/updateManifest.js +++ /dev/null @@ -1,102 +0,0 @@ -var fs = require('fs'); -// update android permissions in manifest file -let permissiontags = ` - - - - - - - - ` - -let manifestPath = 'android/app/src/main/AndroidManifest.xml'; -checkFileAndUpdate(permissiontags, manifestPath, "manifest") - -// proguard text -let proguardTxt = `# Please add these rules to your existing keep rules in order to suppress warnings. -# This is generated automatically by the Android Gradle plugin. --dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue --dontwarn com.google.errorprone.annotations.CheckReturnValue --dontwarn com.google.errorprone.annotations.Immutable --dontwarn com.google.errorprone.annotations.RestrictedApi --dontwarn javax.annotation.Nullable --dontwarn javax.annotation.concurrent.GuardedBy --keep class net.sqlcipher.** { *; } --keep class net.sqlcipher.database.* { *; } -` -let proguardPath = 'android/app/proguard-rules.pro'; -checkFileAndUpdate(proguardTxt, proguardPath, 'proguard'); - -function checkFileAndUpdate(updateCode, destinationPath, type) { - fs.readFile(destinationPath, 'utf8', (err, data) => { - if (err) { - console.error(err); - return; - } - if (data.match('android:allowBackup="true"')) { - let replacedData = data.replace('android:allowBackup="true"', `android:allowBackup="false" \n \t\tandroid:requestLegacyExternalStorage="true"`) - data = replacedData; - } - if(type == "manifest" && data.match("")){ - let res = data.replace("", updateCode) - fs.writeFile(destinationPath, res, (err) => { - if (err) { - console.error("********* err", err); - } - }); - } - if (type == "proguard" && !data.match("# Please add ")) { - fs.appendFileSync(destinationPath, updateCode, (err) => { - if (err) { - console.error("********* err", err); - } - }); - } - }); -} - -// styles.xml to aviod splashscreen -fs.readFile("android/app/src/main/res/values/styles.xml", 'utf-8', (err, data) => { - if(err) { - console.log(err) - } - if(data.match('@drawable/splash')) { - let replacedData = data.replace('@drawable/splash', ` - true`) - fs.writeFile('android/app/src/main/res/values/styles.xml', replacedData, (err) => { - if (err) { - console.error("********* err", err); - } - }) - } -}) - -// update strings.xml -// fs.readFile("android/app/src/main/res/values/strings.xml", 'utf-8', (err, data) => { -// if(err) { -// console.log(err) -// } - fs.copyFile("configuration/strings.xml", "android/app/src/main/res/values/strings.xml", (err) => { - if(err) { - console.log(err) - } - }) -// }) - -// fs.readFile(proguardPath, 'utf8', (err, data) => { -// if (err) { -// console.error(err); -// return; -// } -// console.log('update proguard '); -// if (data.match("# Please add ")) { - -// } else { -// fs.appendFileSync(proguardPath, proguardTxt, (err) => { -// if (err) { -// console.error("********* err", err); -// } -// }); -// } -// }); \ No newline at end of file diff --git a/package.json b/package.json index fb97eff..0993fa2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "test": "ng test", "lint": "ng lint", "capacitor:copy:before": "node hooks/copyGradleProperties.js android && cat android/app/build.gradle", - "capacitor:sync:before": "node hooks/updateManifest.js android", "ionic-build:ci": "ng build && ionic cap build android --no-open --source-map=true", "ionic-build": "ng build && ionic cap run android --source-map=true --target emulator-5554" }, From 0fb7baedb51487f8145736bc2ddbb0bb04939847 Mon Sep 17 00:00:00 2001 From: swayangjit Date: Wed, 8 May 2024 16:55:07 +0530 Subject: [PATCH 2/2] Issue #DJP-000 chore: Updated scripts --- build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sh b/build.sh index 4e733c4..14e9dd7 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,6 @@ if [[ -f configuration/config.properties ]]; then echo "File exists" # Simple script to clean install rm -rf node_modules - rm -rf android rm -rf www rm package-lock.json