2017-08-07 103 views
1

我正在開發一個Ionic應用程序,我想通過config.xml在AndroidManifest.xml文件中添加android @ autoBackup =「false」。 根據cordova文檔,cordova 6.4支持config.xml中的edit-config標籤,通過它我可以實現類似於plugin.xml的編輯標籤。edit-config在config.xml中不起作用cordova

這就是我寫在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> 

它改變這樣

<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文件在AndroidManifest.xml中上面的代碼,你可以很容易地找到應用標籤已經更新了Android @ AUTOBACKUP =「假」,但還添加了應用程序標記作爲第一個具有autoBackup屬性的子項。 我不希望應用程序標記作爲子標記,我嘗試了很多,但無法找到此問題的根本原因。 任何人都可以建議我,我在這裏做錯了什麼? 在此先感謝。

回答

0

嘗試改變編輯配置標籤的「目標」屬性是這樣的:

<edit-config file="AndroidManifest.xml" target="application" mode="merge"> 

這告訴你要修改一個名爲「應用程序」節點科爾多瓦。有關XPath選擇器的更多詳細信息,請參見XPath

如果這不應該出來,你可以看看cordova-plugin-custom-config。有了這個插件,你可以在首選項標籤簡單地添加到config.xml中的機器人部分像this

<preference name="android-manifest/@android:allowBackup" value="false" /> 
+0

我同意你的建議試過,但還是我得到了同樣的問題。我以前使用過的建議插件及其工作預期,但我不想再使用此插件,即使我從「cordova-plugin-custom-config」插件文檔[here](https:// github。 com/dpa99c/cordova-custom-config#android-preferences)。 –

+0

您可以嘗試將目標屬性更改爲'/ *'或'/ manifest/*'嗎?也許它必須是絕對路徑。我可以問使用custom-config插件有什麼問題嗎?在更改目標屬性後, – David

+0

仍然會出現相同的問題。 custom-config插件沒有特定的原因,因爲我們只需要嚮應用程序標籤添加一個屬性,現在我們正在使用[email protected],這就是爲什麼我們試圖在沒有插件的情況下實現它。如果沒有任何進展,我們可以繼續使用定製配置插件。非常感謝您的持續幫助。 –

相關問題