Realm Cloud Add Initial Data


#1

Is there any extra steps needed to setup Realm Cloud that is different from self-hosted ROS. I am trying to add initial data from Android to Realm Cloud without success. I can see that the data is added locally but not on the cloud. The actual method that adds the data is a simple Realm Transaction that has been used numerous times to add initial data to self-hosted ROS.

Here is a the simple attempt to seed Realm cloud, with an existing user account.

public class MainActivity extends AppCompatActivity {

    private static final String INSTANCE_ADDRESS = "appname-app.us1.cloud.realm.io";
    public static final String AUTH_URL = "https://" + INSTANCE_ADDRESS + "/auth";
    public static final String REALM_URL = "realms://" + INSTANCE_ADDRESS;

    public static final String TAG = "MainActivity";
    private Realm realm;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Realm.init(this);

        SyncUser user = SyncUser.currentUser();
        if (user != null){
            loadIntialData();
        } else {
            loginAnonymously();
        }
    }
   

  private void loginAnonymously() {
        SyncUser.loginAsync(SyncCredentials.usernamePassword("[email protected]",
                "fancypwd", false), AUTH_URL, new SyncUser.Callback<SyncUser>() {
            @Override
            public void onSuccess(SyncUser user) {
                Log.d(TAG, "Login succeeded")
                loadIntialData();
            }

            @Override
            public void onError(ObjectServerError error) {
                Log.d(TAG, error.getErrorMessage());
            }
        });
    }


    private Realm setUpRealm() {
        Log.d(TAG, "setUpRealm");
        SyncConfiguration configuration = new SyncConfiguration.Builder(
                SyncUser.currentUser(),
                INSTANCE_ADDRESS + "/posts").build();
        Realm realm = Realm.getInstance(configuration);

        return realm;
    }

    private void loadIntialData() {
 
        Log.d(TAG, "loadIntialData");
        realm = setUpRealm();
        saveInitialData(realm);
  }
}

Sync is enabled in gradle file and I am using classpath “io.realm:realm-gradle-plugin:5.0.0-BETA1”

What step am I missing?


#2

The ROS instance running in cloud is based on the current stable version of ROS which is incompatible with the beta version of the Java SDK. If you downgrade the Java SDK to a stable version, you should be able to get things to sync.


#3

Thank you, that worked. Its interesting the demo app for Cloud is using beta. https://git.io/vAhUx