objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

openStore gets stuck after updating to a new release of the app

Open TMcClain5 opened this issue 3 years ago • 4 comments

When first installing a version of the app, openStore works as expected and creates the store and boxes as needed on launch. After updating the app on the phone it gets stuck on the launch screen and never gets past it.

The only way to get past the issue is to delete the App removing all data and then reinstall from there.

Basic info (please complete the following information):

  • ObjectBox version: 1.6.2
  • Flutter/Dart SDK: Flutter 3.3.3
  • Null-safety enabled: yes
  • Reproducibility: every new release
  • OS: iOS, may occur also in Android but only able to test in iOS
  • Device/Emulator: iPhone X / iPad Air 4th gen

Steps to reproduce

  1. Build first version of app with object box and install to phone, it works fine
  2. Build second version of app, rerunning "flutter pub run build_runner build" without making any changes to app
  3. Update app to this new version, and app will get stuck on the launch screen

Expected behavior

Build new release and push to TestFlight without having to delete the app to get the app to Launch

Code

If applicable, add code to help explain your problem.

main.dart 
late ObjectBox objectBox;
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  objectBox = await ObjectBox.create();
  runApp(const MyApp());
}

object_box.dart
class ObjectBox {
  /// The Store of this app.
  late final Store store;

  late final Box<Animal> animalBox;
  late final Box<Dog> dogBox;
  late final Box<Cat> catBox;

  ObjectBox._create(this.store) {
    animalBox = Box<Animal>(store);
    dogBox = Box<Dog>(store);
    catBox = Box<Cat>(store);
  }

  /// Create an instance of ObjectBox to use throughout the app.
  static Future<ObjectBox> create() async {
    final docsDir = await getApplicationDocumentsDirectory();
    // Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
    final store = await openStore(directory: join(docsDir.path, "animal-db"));
    return ObjectBox._create(store);
  }
}

TMcClain5 avatar Oct 05 '22 16:10 TMcClain5

Thanks for reporting. Is there any log output when launching the app, e.g. an exception stack trace?

Do you make sure to preserve the ObjectBox model file between builds?

greenrobot-team avatar Oct 10 '22 06:10 greenrobot-team

I am keeping the model file and it is committed to my repository. I currently have no way to access the stack trace from the Device.

TMcClain5 avatar Oct 11 '22 17:10 TMcClain5

Thanks! However, without a stack trace or specific error message I can't really tell what's wrong.

My best guess based on the behavior is that the model file of your app was changed in an incompatible way (e.g. by merging changes from multiple branches). This problem and the solution is described in more detail at https://docs.objectbox.io/advanced/meta-model-ids-and-uids#resolving-meta-model-conflicts.

greenrobot-team avatar Oct 12 '22 08:10 greenrobot-team

Thank you, I'll look into that and see if that can fix my issue. If not, I'll figure out a way to get the stack trace.

TMcClain5 avatar Oct 12 '22 13:10 TMcClain5

@TMcClain5 this happened to me mostly when changing a data type in my models, e.g.

From

class SomeModel {
  int count;
}

To

class SomeModel {
  double count;
}

techouse avatar Oct 20 '22 09:10 techouse

Yes, I believe I have addressed the issue following the link sent above. Somehow the models file got corrupted and it just needed to be blown away and recreated and then everything worked fine!

TMcClain5 avatar Oct 21 '22 14:10 TMcClain5