edit-config在cordova的config.xml中不起作用 [英] edit-config is not working in config.xml in cordova
问题描述
我正在开发一个Ionic应用程序,我想通过config.xml在AndroidManifest.xml文件中添加android @ autoBackup =false。
根据cordova文档,cordova版本6.4支持config.xml中的edit-config标记,通过它我可以实现类似于plugin.xml的功能。
I am working on an Ionic app and i want to add android@autoBackup="false" in AndroidManifest.xml file through config.xml. As per the cordova documentation, cordova version 6.4 supports edit-config tag in config.xml through which i can achieve this similar to plugin.xml.
这是我在config.xml文件中写的。
This is what i have written in config.xml file.
<platform name="android">
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:autoBackup="false" />
</edit-config>
<icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
<icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
<splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
<splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
<splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
</platform>
它会像我这样改变我的AndroidManifest.xml文件
And it changes my AndroidManifest.xml file like this
<application android:autoBackup="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<application android:autoBackup="false" />
<activity android:exported="true" android:launchMode="singleTop" android:name="com.gae.scaffolder.plugin.FCMPluginActivity">
<intent-filter>
<action android:name="FCM_PLUGIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.gae.scaffolder.plugin.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</application>
在上面的AndroidManifest.xml代码中,您可以轻松找到已使用android @ autoBackup更新的应用程序标签=false但还添加了应用程序标记作为第一个具有autoBackup属性的子项。
我不希望应用程序标记作为子标记,我尝试了很多,但找不到此问题的根本原因。
有谁能告诉我这里我做错了什么?
提前致谢。
In above code of AndroidManifest.xml, you can easily find application tag has been updated with android@autoBackup="false" but also added application tag as child of first one with autoBackup attribute. I don't want application tag as child tag, i tried a lot but couldn't find the root cause of this issue. Can anyone suggest me what am i doing wrong here? Thanks in advance.
推荐答案
尝试更改edit-config标签的target属性,如下所示:
Try changing the "target" property of the edit-config tag like this:
<edit-config file="AndroidManifest.xml" target="application" mode="merge">
这告诉cordova您要修改名为application的节点。有关XPath选择器的更多详细信息,请参见 XPath 。
This tells cordova you want to modify a node named "application". See XPath for more details on XPath selectors.
如果这不能解决,你可以看一下 cordova-plugin-custom-config 。使用此插件,您只需将首选项标签添加到config.xml的android部分,如这个:
If this should not work out for you can have a look at cordova-plugin-custom-config. With this plugin you can simply add a preference tag to the android section of config.xml like this:
<preference name="android-manifest/@android:allowBackup" value="false" />
这篇关于edit-config在cordova的config.xml中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!