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.
我希望能够控制AndroidManifest中的“支持屏幕”元素。从Cordova CLI进行构建时的xml文件。
Specifically, I'd like to control the following element within AndroidManifest.xml:
具体地说,我想在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.
理想情况下,我希望在Cordova配置中有可用的设置。可以让我直接控制支持的屏幕大小的xml文件。
I've tried monkeying around with config.xml settings like the following to no avail:
我试着摆弄配置。xml设置如下,但毫无用处:
<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.
我认识到我可以存储定制的android手机。在我的源代码控制中使用Cordova钩子复制xml文件,但是这样做感觉有点笨拙,我担心将来会对配置进行调整。xml文件可能无法进入AndroidManifest。因为我们忘记了在after_prepare钩子期间重写生成的文件。
Is what I'm asking possible using the Cordova CLI? If so, a sample of the config.xml to achieve this would be appreciated.
用Cordova指令,我想问的是可能的吗?如果是这样,配置的一个示例。希望xml能够实现这一点。
2 个解决方案
#1
9
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:
由于最新的cordova > 6.3版本的更改,我们应该能够使用新的编辑-配置标记来编辑Android Manifest。mf文件如下:
<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.
您还需要向config.xml中的小部件元素添加xmlns:android=“http://schemas.android.com/apk/res/android”。
更多的信息
#2
3
As far as I know, hooks are the way to do this. The yeoman iconic framework generator has a great example of this which can take many android specific tags and copy them over to the generated config.xml. See this file here from this slick ionic generator.
就我所知,钩子就是这样做的。yeoman图标框架生成器有一个很好的例子,它可以使用许多android特定的标记并将它们复制到生成的config.xml中。从这个光滑的离子发生器看到这个文件。
Config.xml example from code (https://github.com/diegonetto/generator-ionic/blob/master/templates/hooks/after_prepare/update_platform_config.js):
配置。代码中的xml示例(https://github.com/diegonetto/generator- ionic/blob/master/templates/hooks/after_prepare/update_plat_plat_config .js):
<config-file target="AndroidManifest.xml" parent="/*>
<supports-screens
android:xlargeScreens="false"
android:largeScreens="false"
android:smallScreens="false" />
<uses-permission android:name="android.permission.READ_CONTACTS" android:maxSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
</config-file>
Hooks can be automatically run from the hooks folder, and this particular hook would reside in hooks/after_prepare, or in the config as <hook type="after_prepare" src="path/to/file/update_platform_config.js" />
钩子可以自动从钩子文件夹中运行,而这个特殊的钩子将驻留在钩子/after_prepare中,或者在配置中作为
More documentation on hooks can be found in the hooks readme: http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html#Hooks%20Guide
关于钩子的更多文档可以在钩子readme中找到:http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html# hooks %20Guide
Edit: update git repositories for generator and cordova docs.
编辑:为生成器和cordova文档更新git仓库。
#1
9
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:
由于最新的cordova > 6.3版本的更改,我们应该能够使用新的编辑-配置标记来编辑Android Manifest。mf文件如下:
<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.
您还需要向config.xml中的小部件元素添加xmlns:android=“http://schemas.android.com/apk/res/android”。
更多的信息
#2
3
As far as I know, hooks are the way to do this. The yeoman iconic framework generator has a great example of this which can take many android specific tags and copy them over to the generated config.xml. See this file here from this slick ionic generator.
就我所知,钩子就是这样做的。yeoman图标框架生成器有一个很好的例子,它可以使用许多android特定的标记并将它们复制到生成的config.xml中。从这个光滑的离子发生器看到这个文件。
Config.xml example from code (https://github.com/diegonetto/generator-ionic/blob/master/templates/hooks/after_prepare/update_platform_config.js):
配置。代码中的xml示例(https://github.com/diegonetto/generator- ionic/blob/master/templates/hooks/after_prepare/update_plat_plat_config .js):
<config-file target="AndroidManifest.xml" parent="/*>
<supports-screens
android:xlargeScreens="false"
android:largeScreens="false"
android:smallScreens="false" />
<uses-permission android:name="android.permission.READ_CONTACTS" android:maxSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
</config-file>
Hooks can be automatically run from the hooks folder, and this particular hook would reside in hooks/after_prepare, or in the config as <hook type="after_prepare" src="path/to/file/update_platform_config.js" />
钩子可以自动从钩子文件夹中运行,而这个特殊的钩子将驻留在钩子/after_prepare中,或者在配置中作为
More documentation on hooks can be found in the hooks readme: http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html#Hooks%20Guide
关于钩子的更多文档可以在钩子readme中找到:http://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html# hooks %20Guide
Edit: update git repositories for generator and cordova docs.
编辑:为生成器和cordova文档更新git仓库。