Member-only story

Automatic Google Drive backup for Android’s React Native

Davyd NRB
2 min readDec 28, 2022

What if async storage values were to persist when a user changed devices or installed an app again?

You won’t believe it, but it works with Android right out of the box!

First we need to enable a backup option in the android/app/src/main/AndroidManifest.xml file:

    <application
android:allowBackup="true"
android:dataExtractionRules="@xml/backup_rules"

docs: android:allowBackup=["true" | "false"]

Then create android/app/src/main/res/xml/backup_rules.xml file with the list of files that should be added to backup:

<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup>
<!-- your rules -->
</cloud-backup>
<device-transfer>
<!-- your rules -->
</device-transfer>
</data-extraction-rules>

docs: Backup and restore

Testing

More rules are listed below, but first, let’s look at how to test them.

  1. You can use Simulator or Real device
  2. Need to enable Backups: Setting => System => Backup
  3. Then using adb you can create/restore backup:
# Replace `com.mycompany.myapp` with your app package!!!
adb shell bmgr…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Davyd NRB
Davyd NRB

Written by Davyd NRB

React Native guru 🧘\ DevOps adjutant \ Linux lover ❤️

No responses yet

Write a response