flutterdartflutter-dependenciesobjectboxflutter-objectbox

Flutter Object box crashing on Release


Flutter android app integrated with ObjectBox 1.6.0 works on debug mode but crashes on Release build on Android 10 and above.

class ObjectBox {
  /// The Store of this app.
  late final Store store;
  
  ObjectBox._create(this.store) {
    // Add any additional setup code, e.g. build queries.
  }

  /// Create an instance of ObjectBox to use throughout the app.
  static Future<ObjectBox> create() async {
    // Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
    final store = await openStore();
    return ObjectBox._create(store);
  }
}

It says failed to create store and app stucks on splash screen.


Solution

  • I think Objectbox doesn't have permission to write to the default location in the android 10 ad above. What I have tried is pass the location to open store. The directory can be get using path_provider. Modify the create method as follows

    static Future<ObjectBox> create() async {
        // Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
        Directory dir = await getApplicationDocumentsDirectory();
        final store = await openStore(directory: dir.path);
        return ObjectBox._create(store);
      }