Changing config.xml with no effect


I am having an issue using the config.xml. Whatever changes I make does not translate into anything in the app itself. For example, when I try to lock the orientation into portrait mode using: it does not work.

I am using the CLI to build and have tried changing the location of the config.xml to the project root instead of the www-folder according to another thread, which sadly does not work either.

I am on Android 4.2.2 using Cordova 3.4.0-0.19.7.

I have tried different projects and even tried the demos and it simply will not work. I am currently at a loss here and would greatly appreciate any help I can get! :slight_smile:

1 Like

The device orientation lock is a known problem that was supposed to be fixed in 3.4.0 ( but I am having some problem getting it to work as shown. Device still loads app in portrait mode while I have set it to go to landscape.

It seems the cordova-cli still doesn’t add the <preference name="Orientation" value="landscape" /> preference to the build process. You can follow the issue here:

I found a way that kinda works.

  1. Update the node_modules/cordova/src/ConfigParser.js by replacing the function getPreference with the equivalent function from here:
  1. Add your orientation lock preference in config.xml: <preference name="Orientation" value="landscape" />

  2. This will now add the android:screenOrientation preference to your AndroidManifest.xml file. However, what you will find is that if you specify landscape orientation in your confog.xml, Cordova will write userLandscape into your AndroidManifest.xml file. This doesn’t work as expected according to What userLandscape does is to force portrait lock in my device: weird behaviour. There is a way to fix this as well:

  • open node_modules/cordova/src/metadata/android_parser.js file
  • find the like that says if (orientationPref) {
  • inside that block, replace the line for the landscape case from userLandscape to this:
    act.attrib["android:screenOrientation"] = 'landscape';

This days it can be simply done with a Cordova net.yoik.cordova.plugins.screenorientation plugin.


// set to either landscape

// allow user rotate

Find more about it here, there’s even a working example you can play with: Gajotres - Best Technology Product Reviews, News, Tips, and Comparison