0

There are several good posts (eg this) instructing how to set this in AndroidManifest.xml.

However, I find that Xamarin (Visual Studio) automatically (re-)generates the AndroidManifest.xml file at build time, using the [Activity()] attributes (== Properties > Android Manifest) to generate the manifest's <application> tag+attribs.

Thus if you manually edit the AndroidManifest.xml to add the android:allowBackup attrib, it will get lost upon rebuild.

Additionally, [Activity()] doesn't support allowBackup or fullBackupOnly, so you can't set them them via that.

What's the solution to this?
How can I set android:allowBackup in a way that survives rebuild?

dlchambers
  • 3,511
  • 3
  • 29
  • 34

1 Answers1

1

Just as SushiHangover mentioned, we can use Application Element to achieve this.

The Android manifest also provides a way for you to declare properties for your entire application. This is done via the element and its counterpart, the Application custom attribute. For example, the following Application attribute is added to AssemblyInfo.cs to indicate that the application can be debugged, that its user-readable name is My App, and that it uses the Theme.Light style as the default theme for all activities:

[assembly: Application (Debuggable=true,   
                        Label="My App",   
                        Theme="@android:style/Theme.Light")]

In addition, the Application element is not the only way to configure <application> attributes. Alternately, you can insert attributes directly into the <application> element of Properties/AndroidManifest.xml. These settings are merged into the final <application> element that resides in obj/Debug/android/AndroidManifest.xml.

Note that the contents of Properties/AndroidManifest.xml always override data provided by custom attributes.

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • Where is the [assembly: Application()] attribute applied? In which file, on which class? MSFT docs describe the attribute, but don't say where to put it. – dlchambers Jun 30 '21 at 12:16
  • It's in file `AssemblyInfo.cs` which is in folder `Properties`.Note: You can declare `` properties either in `Properties/AssemblyInfo.cs` or `Properties/AndroidManifest.xml`. – Jessie Zhang -MSFT Jul 01 '21 at 03:03