Android autoBackup feature not working

I’m having an issue with the android Back up user data with Auto Backup  |  Identity  |  Android Developers feature not working.
Unity version; 2018.4.3f1
Android; min version: 16, target: 28

Partial manifest which includes the allowBackup flag;

<application android:allowBackup="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:largeHeap="true" android:theme="@style/UnityThemeSelector" android:resizeableActivity="false"
android:isGame="true" android:banner="@drawable/app_banner" android:networkSecurityConfig="@xml/network_security_config">
        <!-- Required for "super widescreen" devices -->
        <meta-data android:name="android.max_aspect" android:value="3.0" />
        <activity android:label="@string/app_name" android:name=REDACTED android:screenOrientation="sensorPortrait" android:launchMode="singleTop" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:clearTaskOnLaunch="false">
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
</application>

I’ve tried it with the ‘android:fullBackupOnly’ flag, but it made no difference either.

  • It won’t retain anything in Playerprefs upon uninstall.
  • It won’t retain anything when manually saving it in the native android sharedPreferences and uninstalling.
  • Builds have been created using the same bundle identifier as used for our store product.
  • We force our backups by manually triggering the google drive backup on the phone to ensure it attempted to do the backup.
  • We have multiple manifests which get merged together, but we’ve looked in our final merged manifest and it is still the same as shown in the example above.

Any help with this would be greatly appreciated, as I’m not sure where to go from here.

So in the end it was a quota issue. For anyone who kind of missed the documentation like I did, here are easy steps to determine what error you’re dealing with;

https://developer.android.com/studio/command-line/adb.html

  • navigate to your android SDK folder.
  • open a shell/cmd window.
  • List the packages installed on your device, to get the package which you’re expecting to perform an autobackup " .\adb shell pm list packages -f ".
  • Open LogCat to get the full debug.
  • Test ADB auto backup .\adb shell bmgr backupnow “PACKAGE_NAME”
  • Read output in shell/cmd and logcat to determine issue.

Good luck :).

Quota is not mentioned on that documentation page? Can you elaborate?

No problem;

The issue that I had is described on the android documentation page ; https://developer.android.com/guide/topics/data/autobackup

Caution: If the amount of data is over 25MB, the system calls onQuotaExceeded() and doesn’t back up data to the cloud. The system periodically checks whether the amount of data later falls under the 25MB threshold and continues Auto Backup when it does.”

I didn’t see this was my issue until I properly hooked it up as the steps described above. I’m still not 100% sure why this is the case, as I don’t think we’re trynig to store anything massive besides our games, but my hunch is that somehow our asset bundles were automatically being rolled up in the backup (which is not what we want).

Anywho, to resolve our issue, I added the following to our manifest;

(Shortened manifest to only include the relevant information)

<application android:allowBackup="true" android:fullBackupContent="@xml/custom_backup_rules" tools:replace="android:fullBackupContent">
</application>

So we still have the allowBackup flag, but also we specify custom rules for our backup. In here we are going specify we only want to save the android sharedprefs ( which is where the Unity PlayerPrefs automatically get saved to on android).
The final thing which was important for us, is the “tools:replace”. The reason for this is because we’re merging several manifests, and one of our plugins was already specifying custom backup rules, even though they were not needed. So we have to override them to make use of our own.

Finally, our custom backup rules is super simple, 100% copy pasta’d from the android documentation;

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="."/>
</full-backup-content>

Now when I use the debug options as described above, we get back a successful backup :). Note that we still seem to see weird results when deploying through AppCenter, but I have a feeling that might just be some weirdness until deploying to the internal track testing.

1 Like