Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add android:largeHeap = "true" in manifest file using Plugin.xml file in phonegap plugin

How can we add android:largeHeap to true in manifest file using plugin.xml file in android phonegap

like image 476
sathish Avatar asked Apr 01 '15 06:04

sathish


1 Answers

A solution that worked for us was doing this with a Cordova/PhoneGap Hook.

Create a hook at the following path

{app-root}/hooks/after_prepare directory/010-update-android-manifest.js

Important to make this file executable

chmod +x 010-update-android-manifest.js

#!/usr/bin/env node

var fs    = require('fs');
var async = require('async');
var exec  = require('child_process').exec;
var path  = require('path');

var root = process.argv[2];
var androidManifest = path.join(root, 'platforms/android/AndroidManifest.xml');
fs.exists(path.join(root, 'platforms/android'), function(exists) {
    if(!exists) return;
    fs.readFile(androidManifest, 'utf8', function(err, data) {
        if(err) throw err;

        var lines = data.split('\n');
        var searchingFor = '<application android:hardwareAccelerated="true"';
        var newManifest = [];
        var largeHeap = 'android:largeHeap="true"';
        lines.forEach(function(line) {
            if(line.trim().indexOf(searchingFor) != -1 && line.trim().indexOf(largeHeap) == -1) {
                newManifest.push(line.replace(/\>$/, ' ') + largeHeap + ">");
            } else {
                newManifest.push(line);
            }
        });

        fs.writeFileSync(androidManifest, newManifest.join('\n'));
    });
});

This will append android:largeHeap="true" to the application tag.

Build your app

cordova build

like image 127
hevets Avatar answered Oct 04 '22 11:10

hevets