Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I control the <supports-screen> setting of an AndroidManifest.xml file from my Cordova config.xml?

I would like to be able to control the "supports-screens" element within the AndroidManifest.xml file when doing a build from the Cordova CLI.

Specifically, I'd like to control the following element within AndroidManifest.xml:

    <supports-screens android:anyDensity="true" 
    android:largeScreens="true" 
    android:normalScreens="true" 
    android:resizeable="true" 
    android:smallScreens="true" 
    android:xlargeScreens="true" />

Ideally, I'm hoping that there is a setting available within the Cordova config.xml file that would let me directly control the supported screen sizes.

I've tried monkeying around with config.xml settings like the following to no avail:

<platform name="android">
    <supports-screen xlargeScreens="false"/>
</platform>

I recognize that I can store a customized AndroidManfiest.xml file in my source control and simply copy it around using a Cordova hook, but doing so feels a bit clunky, and I'm worried that future tweaks to the config.xml file might then not make it into the AndroidManifest.xml because we forgot that we're overwriting the generated file during an after_prepare hook.

Is what I'm asking possible using the Cordova CLI? If so, a sample of the config.xml to achieve this would be appreciated.

like image 866
RMD Avatar asked May 12 '15 22:05

RMD


People also ask

What is the role of config xml file of Cordova project?

config. xml is a global configuration file that controls many aspects of a cordova application's behavior. This platform-agnostic XML file is arranged based on the W3C's Packaged Web Apps (Widgets) specification, and extended to specify core Cordova API features, plugins, and platform-specific settings.

Which of the following are the elements of config xml file of Cordova?

The name of the app that we specified when creating the app. Description for the app. Author of the app. The app's starting page.

When should you use the xml configuration?

An XML configuration file can constrain how an application may override the values supplied in the XML configuration file. It can also restrict which topics the application may publish and subscribe to. These two use cases are handled slightly differently.

How do I add a plugin to config xml Cordova?

When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.


1 Answers

Since this change in the latest cordova > 6.3 versions, we should be able to use the new edit-config tag to edit the Android Manifest.mf file like this:

<edit-config file="AndroidManifest.xml" target="/manifest/supports-screens" mode="merge">
   <supports-screens android:resizeable=["true"| "false"]
                     android:smallScreens=["true" | "false"]
                     android:normalScreens=["true" | "false"]
                     android:largeScreens=["true" | "false"]
                     android:xlargeScreens=["true" | "false"]
                     android:anyDensity=["true" | "false"]
                     android:requiresSmallestWidthDp="integer"
                     android:compatibleWidthLimitDp="integer"
                     android:largestWidthLimitDp="integer"/>
</edit-config>

Also you'll need to add xmlns:android="http://schemas.android.com/apk/res/android" to the widget element in config.xml.

More info there and there

like image 112
Żabojad Avatar answered Oct 28 '22 12:10

Żabojad