Modify Android Manifest using hook


#1

I wan to modify android:windowSoftInputMode value from adjustResize to adjustPan. I’ve used the below hook update_androidManifest.js :

#!/usr/bin/env node

// http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/
// this hook replaces arbitrary text in arbitrary files
// 
//  - To import "LogGrabber.h" class in Application PCH file.
//
// Author Varghese Abraham
//
module.exports = function(context) {
	var fs = require('fs');
	var path = require('path');
	var glob = require('glob');

	var rootdir;
    if(context.opts.paths && context.opts.paths.length > 1){
        rootdir = path.join(context.opts.paths[0], "..");
    }else if(context.opts.projectRoot){
        rootdir = context.opts.projectRoot;
    }
	console.log("STARTING IN: " + rootdir);

	function replace_string_in_file(filename, to_replace, replace_with) {
		var data = fs.readFileSync(filename, 'utf8');
		var result = data.replace(new RegExp(to_replace, "g"), replace_with);
		fs.writeFileSync(filename, result, 'utf8');
	}
    
    function find_string_in_file(filename, to_find) {
        var data = fs.readFileSync(filename, 'utf8');
        var result = data.includes(to_find);
        return result;
    }
 	
    if (rootdir) {
        //Update <Appname>-Prefix.pch file to import RPCLibrary LogGrabber class
        var appPCHFile = glob.sync("**/*-AndroidManifest.xml", {
            "cwd": rootdir
        });
        appPCHFile.forEach(function(nfo, idx, array) {
            // Skip the PCH files generated by cordova/npm
            if (nfo &&
                (nfo.indexOf("build") > -1 ||
                    nfo.indexOf("node_modules") > -1 ||
                    nfo.indexOf("plugins") > -1 ||
                    nfo.indexOf("xcarchive") > -1)) {
                return;
            }

            var replceText = "adjustResize";
            var logGrabberImport = "adjustPan";
            var fullfilename = path.join(rootdir, nfo.toString());

            console.log("File to update " + fullfilename);
            console.log("Replace \"" + replceText + "\" with \n" + logGrabberImport);

            if (fs.existsSync(fullfilename)) {
                //Check if "LogGrabber.h" is already imported or not
                if (find_string_in_file(fullfilename, logGrabberImport)) {
                    console.log("LogGrabber already imported");
                    return;
                }
                //Replace the texts
                replace_string_in_file(fullfilename,
                    replceText,
                    logGrabberImport);
            } else {
                console.log("missing: " + fullfilename);
            }
        });

    }
} 

I’ve included the below lines to my config.xml:

<hook type="after_build/" src="hooks/after_build/update_androidManifest.js" />

When I run the command to create an android build, the android Manifest.xml file does not get modified. Am I missing something here or should I run extra command before building the apk file.

Thanks in advance.