Android 从 Parse 切换到 Parse Server 崩溃

Android switch from Parse to Parse Server crashes

我正在将我的 Android 和 iOS 应用程序从 Parse.com 迁移到 Parse Server。首先,我正在使用测试应用程序进行迁移,以确保一切正常。 使用 iOS 没有问题,但是使用 Android 每次用户进入应用程序时更新的应用程序都会崩溃。

这是更新的 Android 代码:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    //Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey(null)
            .server("https://<my new server>/parse/")
            .build()
    );
    ParseUser.enableRevocableSessionInBackground();
}

崩溃 returns a "com.parse.ParseException: java.lang.IllegalStateException: unable to encode an association with an unsaved ParseObject",考虑到我在 Whosebug 中阅读的内容,这是因为 ParseUser.getCurrentUser() returns null(尽管用户已登录)并且解析方法失败。

事实上,如果我使用相同的代码,取消注释旧版本的 Parse.initialize,注释新版本的 Parse.initialize,编译并启动应用程序,启动没有问题,并且用户可以正常使用。

但是,如果我再次注释旧版本的 Parse.initialize,取消注释新版本的 Parse.initialize,编译并启动应用程序,这会立即崩溃,因为 ParseUser.getCurrentUser() returns null 和 Parse 方法失败。

我在这里错过了什么?我应该强制我的用户重新登录吗?这在我看来是一个糟糕的用户体验,无论如何,在 iOS 我对新版本没有任何问题,这两个平台之间有什么区别?

编辑 1:

根据 Robert Rowntree 的建议,我将初始化更改为:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    //Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey("<my client key>")
            .server("https://<my new server>/parse/")
            .build()
    );
    //Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
    Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
    ParseUser.enableRevocableSessionInBackground();
}

除此之外,我检查过我的 Parse 版本是最后可用的,我的 gradle 文件中有这个:

compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

结果是一样的,应用程序崩溃 "com.parse.ParseException: java.lang.IllegalStateException: unable to encode an association with an unsaved ParseObject" 我第一次调用 Parse。 除此之外,我能看到的与parse相关的唯一日志是与GCM令牌相关的,没有别的。

编辑 2:

我尝试了另一件事,使用旧的初始化卸载应用程序并使用新的初始化安装它,我猜新版本现在可以运行了。

但是,这当然不是我的解决方案,我不能告诉我的用户卸载应用程序并重新安装。

但这是一个提示:新的初始化没有问题,但是旧的 Parse "reacts" 使用新的 Parse Server 打开应用程序时,getCurrentUser 或类似的东西肯定有任何不一致那。

你能试试这样初始化吗:

Parse.initialize(new Parse.Configuration.Builder(this)
                        .applicationId("APP_ID")
                        .clientKey("CLIENT_KEY")
                        .server("https://SERVER_URL/parse/") // The trailing slash is important.
                        .enableLocalDataStore()
                        .build()
                );

注意

.enableLocalDataStore()

正在初始化中。删除这个:

Parse.enableLocalDatastore(app);