#!/usr/bin/env node

module.exports = function(context) {
  throw new Error('Check AllowBacup plugin start work');
  var fs = context.requireCordovaModule('fs'),
    path = context.requireCordovaModule('path');

  var platformRoot = path.join(context.opts.projectRoot, 'platforms/android');


  var manifestFile = path.join(platformRoot, 'AndroidManifest.xml');

  if (fs.existsSync(manifestFile)) {

    fs.readFile(manifestFile, 'utf8', function (err,data) {
      if (err) {
        throw new Error('Unable to find AndroidManifest.xml: ' + err);
      }
      var appClass = ' android:allowBackup="true" ';
      if (data.indexOf(appClass) == -1) {
        var result = data.replace(/<application/g, '<application ' + appClass);
        fs.writeFile(manifestFile, result, 'utf8', function (err) {
          if (err) throw new Error('Unable to write into AndroidManifest.xml: ' + err);
        })
      }
    });
  }


};

@@ -1,25 +1,4 @@
-#!/usr/bin/env node%0A%0A
 modu
@@ -24,93 +24,69 @@
 on(c
-ontext) %7B%0A  throw new Error('Check AllowBacup plugin start work');%0A  var fs = context
+tx) %7B%0A  var fs = ctx.requireCordovaModule('fs'),%0A  path = ctx
 .req
@@ -108,32 +108,27 @@
 le('
-fs
+path
 '),%0A  
-  path = context
+xml = ctx
 .req
@@ -150,35 +150,55 @@
 le('
-path')
+cordova-common').xmlHelpers
 ;%0A%0A
- 
  var 
-platformRoot
+manifestPath
  = p
@@ -211,14 +211,10 @@
 in(c
-ontex
 t
+x
 .opt
@@ -250,460 +250,325 @@
 roid
-');%0A%0A%0A  var manifestFile = path.join(platformRoot, 'AndroidManifest.xml');%0A%0A  if (fs.existsSync(manifestFile)) %7B%0A%0A    fs.readFile(manifestFile, 'utf8', function (err,data) %7B%0A      if (err) %7B%0A        throw new Error('Unable to find AndroidManifest.xml: ' + err);%0A      %7D%0A      var appClass = ' android:allowBackup=%22true%22 ';%0A      if (data.indexOf(appClass) == -1) %7B%0A        var result = data.replace(/%3Capplication/g, '%3Capplication ' + appClass);%0A       
+/AndroidManifest.xml');%0A var doc = xml.parseElementtreeSync(manifestPath);%0A if (doc.getroot().tag !== 'manifest') %7B%0A    throw new Error(manifestPath + ' has incorrect root node name (expected %22manifest%22)');%0A %7D%0A%0A doc.getroot().find('./application').attrib%5B'android:allowBackup'%5D = %22false%22;%0A%0A //write the manifest file%0A
  fs.
@@ -576,16 +576,20 @@
 riteFile
+Sync
 (manifes
@@ -593,167 +593,54 @@
 fest
-File, result, 'utf8', function (err) %7B%0A          if (err) throw new Error('Unable to write into AndroidManifest.xml: ' + err);%0A        %7D)%0A      %7D%0A    %7D);%0A  %7D%0A%0A
+Path, doc.write(%7B%0A    indent: 4%0A %7D), 'utf-8');
 %0A%7D;%0A

Update androidBeforeInstall.js