diff --git a/config.cordovabuild.xml b/config.cordovabuild.xml index 212485757..6a0c1480e 100644 --- a/config.cordovabuild.xml +++ b/config.cordovabuild.xml @@ -1,5 +1,5 @@ - + emission A commute pattern tracker and carbon footprint estimator. @@ -42,6 +42,9 @@ + + To scan QR codes for the login token and the study + @@ -53,6 +56,7 @@ + diff --git a/hooks/before_build/android/android_change_compile_implementation.js b/hooks/before_build/android/android_change_compile_implementation.js new file mode 100755 index 000000000..0e2e51999 --- /dev/null +++ b/hooks/before_build/android/android_change_compile_implementation.js @@ -0,0 +1,48 @@ +/* + * A hook to change provider in order to match with the application name. + */ + +var fs = require('fs'); +var path = require('path'); +var et = require('elementtree'); + +const LOG_NAME = "Changing compile to implementation "; + +var changeCompileToImplementation = function (file) { + if (fs.existsSync(file)) { + fs.readFile(file, 'utf8', function (err, data) { + var result = data.replace("compile", "implementation"); + fs.writeFile(file, result, 'utf8', function (err) { + if (err) throw new Error(LOG_NAME + 'Unable to write into ' + file + ': ' + err); + console.log(LOG_NAME + "" + file + " updated...") + }); + }); + } else { + console.error("Could not find file "+file+" skipping compile -> implementation change"); + } +} + +module.exports = function (context) { + // If Android platform is not installed, don't even execute + if (!context.opts.platforms.includes('android')) return; + + var config_xml = path.join(context.opts.projectRoot, 'config.xml'); + var data = fs.readFileSync(config_xml).toString(); + // If no data then no config.xml + if (data) { + var etree = et.parse(data); + console.log(LOG_NAME + "Retrieving application name...") + var applicationName = etree._root.attrib.id; + console.info(LOG_NAME + "Your application is " + applicationName); + const splitParts = applicationName.split(".") + var lastApplicationPart = splitParts[splitParts.length - 1]; + + var platformRoot = path.join(context.opts.projectRoot, 'platforms/android/') + + console.log(LOG_NAME + "Updating barcode scanner gradle..."); + var gradleFile = path.join(platformRoot, 'phonegap-plugin-barcodescanner/'+lastApplicationPart+'-barcodescanner.gradle'); + changeCompileToImplementation(gradleFile); + } else { + throw new Error(LOG_NAME + "Could not retrieve application name."); + } +} diff --git a/package.cordovabuild.json b/package.cordovabuild.json index e042b97b1..d067bc1ae 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -1,6 +1,6 @@ { "name": "edu.berkeley.eecs.emission", - "version": "3.2.7", + "version": "3.2.8", "displayName": "emission", "license": "BSD-3-Clause", "repository": { @@ -60,7 +60,9 @@ "cordova-plugin-em-unifiedlogger": {}, "cordova-plugin-em-usercache": {}, "cordova-plugin-androidx-adapter": {}, - "cordova-plugin-barcode-qrscanner": {} + "phonegap-plugin-barcodescanner": { + "ANDROID_SUPPORT_V4_VERSION": "27.+" + } } }, "dependencies": { @@ -87,7 +89,7 @@ "cordova-plugin-x-socialsharing": "6.0.4", "fs-extra": "^9.0.1", "klaw-sync": "^6.0.0", - "cordova-plugin-barcode-qrscanner": "^3.0.12", + "phonegap-plugin-barcodescanner": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner#v8.1.0", "@havesource/cordova-plugin-push": "git+https://github.com/havesource/cordova-plugin-push.git#4.0.0-dev.0" } }