如何移动到适用于 Android 的 Realm 同步协议版本 3?

问题描述

我是 Realm 和 Android 开发的新手,正在尝试从 Atlas 查询文档。我能够成功验证用户身份,但是当我尝试执行查询时,出现以下错误E/REALM_JAVA: Session Error[wss://realm.mongodb.com/]: WRONG_PROTOCOL_VERSION(realm::sync::ProtocolError:105): sync client must have a sync protocol version of at least 3 to sync on this application,but found version 2. Please update your application to use a newer SDK

我目前正在开发 10.4.0 版的 Android Realm SDK 和 Android SDK Platform 30。我已经尝试为两者寻找更新,但它说一切都是最新的。这是我的代码

app.loginAsync(emailPasswordCredentials,it -> {
        if (it.isSuccess()) {
            Log.v("AUTH","Successfully authenticated using an email and password.");
            User user = app.currentUser();
            String partitionValue = "object_id";
            SyncConfiguration config = new SyncConfiguration.Builder(
                    user,partitionValue)
                    .allowQueriesOnUiThread(true)
                    .allowWritesOnUiThread(true)
                    .build();
            uiThreadRealm = Realm.getInstance(config);
            
            //Debugging - testing Realm Sync queries
            Products product = uiThreadRealm.where(Products.class).equalTo("_id",4).findFirst();
            if (product != null) {
                Log.v("AUTH",product.toString());
            }
            Log.v("AUTH",config.toString());
            //in-app functions
 }

有没有人有办法解决这个问题?

解决方法

就我而言,这是由于选择 UUID 作为我的字段的类型,这是“目前 SDK 中不支持的类型,但将在未来版本中提供。” (来自 Monogo 的支持)。

,

对于那些来自 react-native 并得到这种错误的人

同步客户端必须具有至少 3 的同步协议版本才能在此应用程序上同步,但发现版本 2。请更新您的应用程序以使用更新的 SDK

只需在您的终端中进行

npm install realm

然后

cd ios
pod install

小心破坏性更改。

如果需要,请在您的模拟器/模拟器上卸载您的应用程序

npx react-native run-ios

npx react-native run-android

所以对于 Android,我想你也必须更新你的 Realm 包......