Skip to content

Instantly share code, notes, and snippets.

@xemasiv
Created April 12, 2018 12:30
Show Gist options
  • Save xemasiv/91e3f05abbf1beafdee81f7a82d42066 to your computer and use it in GitHub Desktop.
Save xemasiv/91e3f05abbf1beafdee81f7a82d42066 to your computer and use it in GitHub Desktop.
Increase SQLite / RockDB Size

Increase Android AsyncStorage Size in React Native The iOS AsyncStorage implementation has an unlimited amount of space by default. This is not the case on Android, the default size of AsyncStorage is 6MB. This is generally enough for a casual application however there are many cases when you may need more, like when you are using PouchDB async adapter.

To increase the size first locate the /android/app/src/main/java/MainApplication.java file in your React Native application.

We'll first add this import at the top of the MainApplication.java file

import com.facebook.react.modules.storage.ReactDatabaseSupplier;

Your imports may look something like.

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.react.modules.storage.ReactDatabaseSupplier;

Next locate the section that looks like

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }

We need to tell React Native how many bytes we want to allow as the maximum size.

We'll define the number of bytes we want like so

long size = 50L * 1024L * 1024L; // 50 MB If you need more than 50MB change the 50L to your desired amount.

Finally we need to set the size with this line of code.

com.facebook.react.modules.storage.ReactDatabaseSupplier.getInstance(getApplicationContext()).setMaximumSize(size); Our code after combining all changes will look like.

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    long size = 50L * 1024L * 1024L; // 50 MB 
    com.facebook.react.modules.storage.ReactDatabaseSupplier.getInstance(getApplicationContext()).setMaximumSize(size);

  }

Disclaimer This will work but is not recommended. If you need to store a significant amount of data look into using SQLite, PouchDB, Realm, or some other storage method. They will not only store data more efficiently but will also be queryable.

@xemasiv
Copy link
Author

xemasiv commented Apr 12, 2018

src https://codedaily.io/tutorials/4/Increase-Android-AsyncStorage-Size-in-React-Native

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment