How to migrate to the new version of Realm

Asked

Viewed 162 times

0

Hello, I have a simple app from my news site, I found it on Github some time ago and edited it.

However it stopped working on some devices (Android 5.1 up) when it was the fix found that with the latest updates of Android Studio is no longer possible to use the version of Remake I used

classpath 'io.Realm:Realm-Gradle-plugin:1.2.0'

since android-apt has become obsolete and in this version (1.2.0) the same is used.

I tried to upgrade to version 4.3.3 of Realm but the constructor used for the first time changed.

@Override
public void onCreate() {
    super.onCreate();
   mInstance = this;
    // init realm database
    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this)
            .name("wordpress.realm")
            .schemaVersion(0)
            .deleteRealmIfMigrationNeeded()
            .build();
    Realm.setDefaultConfiguration(realmConfiguration);

So I need help adjusting the code above in the new ways

*I am an adventurer in the world of Android development, I have no training in the area all help is welcome

1 answer

0


If you are referring to how to update your Android Studio Gradle you can find the information here:

https://realm.io/docs/java/latest/#installation

If you are referring to making a Migration, you need to search regarding Remall Migration. This Migration is related to changing the version of your database, this occurs by changing the schemaVersion(0) for example to .schemaVersion(1) hence your migration is necessary.

You used .deleteRealmIfMigrationNeeded() If you change the version of the database with this line you delete the information from the previous version (defined by the schemaVersion). Then your database is reset and if you need any prior information the app will crash.

The link below explains how to make an Migration.

https://medium.com/@budioktaviyans/android-Realm-Migration-schema-4fcef6c61e82

Browser other questions tagged

You are not signed in. Login or sign up in order to post.