-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert the QR code plugin to the one that we used before
We tried to migrate from `phonegap-plugin-barcodescanner` to the better supported `cordova-plugin-barcode-qrscanner`. However, I was not able to get the new plugin to work. The OS indicated that the app was accessing the camera, but we were not able to see the preview, even after I added a `show` to the code. e-mission/e-mission-docs#838 (comment) e-mission/e-mission-docs#838 (comment) There doesn't seem to be an option to file issues or to communicate with the creator. So let's fall back to the older `phonegap-plugin-barcodescanner` We restore the `android_change_compile_implementation` hook so that we can change the `compile` to `implementation` and get the plugin to compile. Bonus fix: Add the `NSCameraUsageDescription` via the config.xml so that we don't get a permission issue while running on iOS. Testing done: - Builds on both android and iOS - Scanning launches on both android and iOS - QR codes are scanned on both android and iOS
- Loading branch information
Showing
3 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
hooks/before_build/android/android_change_compile_implementation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters