How to migrate to the new version of Realm

0

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

But it did not work on some devices (Android 5.1 up) when it was the fix I discovered that with the latest updates of Android Studio it is no longer possible to use the version of realm I used

  

classpath 'io.realm: realm-gradle-plugin: 1.2.0'

because android-apt is obsolete and in this version (1.2.0) it is used.

I tried upgrading to version 4.3.3 of Realm, but the builder used the first time it 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 tailoring the above code into new ways

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

    
asked by anonymous 15.02.2018 / 16:27

1 answer

0

If you're referring to how to upgrade the Android Studio gradle you can find the information here:

link

If you are referring to doing a migration, you need to look into realm migration. This migration is related to changing the version of your database, this happens by changing the schemaVersion(0) for example to .schemaVersion(1) your migration is required.

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

The link below explains how to do a migration.

link

    
17.02.2018 / 20:21