Skip to content

Bug: Flutter ObjectBox store cannot open when Kotlin model exists — UID mismatch #1219

@AminSallah

Description

@AminSallah

Description

When using ObjectBox in a Flutter app and also accessing the same database from Android (Kotlin) code (e.g., an AppWidget provider), the store fails to open due to an entity UID mismatch, even though both models share the same fields and types.

Both sides define the same entity Counter with id and value fields, but the generated UIDs differ between Dart’s objectbox.g.dart and Android’s MyObjectBox.java.

Dart error

ObjectBoxException: failed to create store:
Incoming entity ID 1:3702879537994877312 does not match existing UID 6372614592112598027

Even after removing the entire database folder and regenerating both models , the UIDs remain different.


Expected behavior

If both models have the same schema (id and value fields, same types, same entity name), the generated entity UIDs should match, allowing both the Dart and Android code to open the same BoxStore.


Actual behavior

UIDs differ between Dart and Kotlin generators, making it impossible to share the same database between Flutter and native Android code.


Dart model

import 'package:objectbox/objectbox.dart';

@Entity()
class Counter {
@Id()
int id = 0; // ObjectBox assigns id when 0
int value;

Counter({this.id = 0, this.value = 0});

@override
String toString() => 'Counter{id: $id, value: $value}';
}

Kotlin model

package com.example.object_box.model

import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id

@Entity
data class Counter(
@Id var id: Long = 0,
var value: Int = 0
)


Generated UID comparison

Source Entity UID Property UIDs
Dart (objectbox.g.dart) 3702879537994877312 id=7081767577393141001, value=9081267074309558120
Kotlin (MyObjectBox.java) 6372614592112598027 id=3796890794073728955, value=6309849204992249866

Steps to reproduce

  1. Create a Flutter app with objectbox and objectbox_flutter_libs.

  2. Add a Kotlin model with the same fields and generate ObjectBox code.

  3. Build both sides.

  4. Use same database path and try to open the store in both Dart and Kotlin using the same directory.

  5. UID mismatch and SchemaException found in flutter logs when first write .


Environment

Flutter:

Flutter 3.35.5
objectbox: ^5.0.0
objectbox_flutter_libs: ^5.0.0

Android:

objectbox-android: 5.0.0
objectbox-processor: 5.0.0
Reproducible: Always


Additional context

Even with identical schema and matching types (intLong), the entity UIDs are completely different. There appears to be no documented way to manually align UIDs or to instruct both generators to produce matching UIDs for the same model.

If Flutter and Android ObjectBox runtimes are not intended to share a store directly, please clarify this in the documentation — currently it’s not obvious that cross-language schema sharing is unsupported.


  • Is it possible for Flutter and Android (Java/Kotlin) to share the same ObjectBox database?
  • Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Type

      No type

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions