iMicknl / cordova-plugin-openalpr

This Cordova plugin adds support for the OpenALPR (Automatic License Plate Recognition) library, which provides support for retrieving the license plate from a picture.
MIT License
33 stars 23 forks source link

Issue with Cordova Platforms : android 7.0.0 #26

Closed SonnyCampbell closed 5 years ago

SonnyCampbell commented 6 years ago

I'm trying to integrate the cordova-plugin-openalpr with an ionic project. I have installed ionic and cordova from the installation instructions. I started a new project with ionic start MyIonicProject tutorial and then built the project using ionic cordova build android.

I added your plugin using cordova plugin add cordova-plugin-openalpr and when I try to build again it throws the below error. I also tried adding the plugin with ionic cordova plugin add cordova-plugin-openalpr and got the same result.

This error seems to be an incompatibility with cordova-android 7.0.0, as a google of the error indicated that other people had this issue for different plugins because it was incompatible with cordova android 7.0.0.

`

cordova build android cp: copyFileSync: could not write to dest file (code=ENOENT):C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\res\xml\config.xml Parsing C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\res\xml\config.xml failed (node:760) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\res\xml\config.xml' at Object.fs.openSync (fs.js:663:18) at Object.fs.readFileSync (fs.js:568:33) at Object.parseElementtreeSync (C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\cordova\node_modules\cordova-common\src\util\xml-helpers.js:180:27) at new ConfigParser (C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\cordova\node_modules\cordova-common\src\ConfigParser\ConfigParser.js:30:24) at updateConfigFilesFrom (C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\cordova\lib\prepare.js:106:18) at Api.module.exports.prepare (C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\cordova\lib\prepare.js:42:20) at Api.prepare (C:\Users\Sonny\Documents\Code\ionic\TestALPR\platforms\android\cordova\Api.js:192:45) at C:\Users\Sonny\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\prepare.js:106:36 at _fulfilled (C:\Users\Sonny\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54) at self.promiseDispatch.done (C:\Users\Sonny\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30) (node:760) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:760) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. `

Running ionic info gives:

cli packages: (C:\Users\Sonny\AppData\Roaming\npm\node_modules) ionic/cli-utils : 1.19.1 ionic (Ionic CLI) : 3.19.1 global packages: cordova (Cordova CLI) : 8.0.0 local packages: ionic/app-scripts : 3.1.8 Cordova Platforms : android 7.0.0 Ionic Framework : ionic-angular 3.9.2 System: Android SDK Tools : 26.1.1 Node : v9.5.0 npm : 5.6.0 OS : Windows 7 Environment Variables: ANDROID_HOME : C:\Users\Sonny\AppData\Local\Android\sdk Misc: backend : pro

iMicknl commented 6 years ago

Are you sure this is an error related to our plugin? I can't find any error which relate to a plugin file.

melvinversluijs commented 6 years ago

@SonnyCampbell, Unfortunately our plugin does not work with Cordova Adnroid 7.0.0, you will have to downgrade to Cordova Android 6.3.0 with cordova platform add android@6.3.0.

The way JNI files are being loaded into Android has been changed as of version 7.0.0, which renders our plugin useless since it depends on the OpenALPR JNI files.

We do not have any plans to fix this any time soon. So if you fix this yourself in the meantime feel free to create a new Pull Request.

Kind regards, Melvin

jor3l commented 6 years ago

Edit: Forgot to mention, this was on version 1 ->

I was able to get this plugin working with android 7+ by using multiple plugins, the idea is to get the image, use a plugin to save it from base64 to file, here the app will request file permisisons, and you can then pass the file path to openalpr plugin.

To save the image from base64 I'm using: cordova plugin add https://github.com/tate-u/Canvas2ImagePlugin.git and modify the Canvas2ImagePlugin.js with this:

module.exports = {

    saveImageDataToLibrary: function (success, failure, canvas) {
        var defaults = { canvas: null, fileName: "IMG_" + new Date().getTime(), album: 'Apps', success: function () { }, failure: function () { } };
        var settings = Object.assign({}, defaults);

        var imageData = canvas.replace(/data:image\/jpeg;base64,/, '');
        return cordova.exec(success, failure, "Canvas2ImagePlugin", "saveImageDataToLibrary", [imageData, settings.fileName, settings.album]);
    }
};

Then use it like this:

window.canvas2ImagePlugin.saveImageDataToLibrary(
    function(msg){
     cordova.plugins.OpenALPR.scan(msg) ...
    },
    function(error) {},
    base64ImageData
);

Hope this helps.

matbeard commented 6 years ago

Could you possibly give some indication of what's involved in making this plugin compatible with Android 7+?

Is it a case of altering the plugin.xml and placing files in different target folders etc. or is there far more to it than that?

Any advice is much appreciated.