科尔多瓦的config.xml中的edit-config不起作用

kul*_*put 3 cordova ionic-framework

我正在开发一个Ionic应用程序,我想通过config.xml在AndroidManifest.xml文件中添加android @ autoBackup =“ false”。根据cordova文档,cordova版本6.4在config.xml中支持edit-config标记,通过它我可以实现类似于plugin.xml的标记。

这就是我在config.xml文件中编写的内容。

<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>
Run Code Online (Sandbox Code Playgroud)

它会像这样更改我的AndroidManifest.xml文件

<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>
Run Code Online (Sandbox Code Playgroud)

在上面的AndroidManifest.xml代码中,您可以轻松地找到应用程序标签已使用android @ autoBackup =“ false”更新,但也将应用程序标签添加为具有autoBackup属性的第一个子标签。我不希望应用程序标签作为子标签,我尝试了很多,但找不到此问题的根本原因。有人可以建议我我在这里做错了吗?提前致谢。

Dav*_*vid 6

尝试像这样更改edit-config标记的“ target”属性:

<edit-config file="AndroidManifest.xml" target="application" mode="merge">
Run Code Online (Sandbox Code Playgroud)

这告诉cordova您要修改名为“应用程序”的节点。有关XPath选择器的更多详细信息,请参见XPath

如果不能解决问题,请查看cordova-plugin-custom-config。使用此插件,您可以像这样简单地向config.xml的android部分添加一个首选项标签:

<preference name="android-manifest/@android:allowBackup" value="false" />
Run Code Online (Sandbox Code Playgroud)