Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Realm version upgrade error with gradle

We are developing an android application together with an SDK. The SDK is a module for the app. We are using Realm only in the SDK (for now). The only gradle file I've added something about Realm is the sdk build.gradle file. I've added the apply plugin: 'realm-android' on the top of the file and

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:0.90.1"
    } 
}

on the bottom of the file. Everything was compiling and working correctly until we tried to upgrade to the latest version (1.1.0).

If I change the version to 1.0.0 or later, it doesn't compile. Here some error logs: Gradle console:

Note: Processing class TransactionUpdateAPICall
Note: Processing class Address
Note: Creating DefaultRealmModule
PersistentDataManager.java:134: error: no suitable method found for    findAllSorted(String,Sort,String,Sort,String,Sort)
            objects = query.findAllSorted(sorts.get(0).fieldName,sorts.get(0).dir,sorts.get(1).fieldName,sorts.get(1).dir,sorts.get(2).fieldName,sorts.get(2).dir);
                           ^
method RealmQuery.findAllSorted(String,Sort) is not applicable
  (actual and formal argument lists differ in length)
method RealmQuery.findAllSorted(String) is not applicable
  (actual and formal argument lists differ in length)
method RealmQuery.findAllSorted(String[],Sort[]) is not applicable
  (actual and formal argument lists differ in length)
method RealmQuery.findAllSorted(String,Sort,String,Sort) is not applicable
  (actual and formal argument lists differ in length)
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

The Messages window displays also some error messages from the Gradle build:

Error:(134, 32) error: no suitable method found for          findAllSorted(String,Sort,String,Sort,String,Sort)
method RealmQuery.findAllSorted(String,Sort) is not applicable
(actual and formal argument lists differ in length)
method RealmQuery.findAllSorted(String) is not applicable
(actual and formal argument lists differ in length)
method RealmQuery.findAllSorted(String[],Sort[]) is not applicable
(actual and formal argument lists differ in length)
method RealmQuery.findAllSorted(String,Sort,String,Sort) is not applicable
(actual and formal argument lists differ in length)
Error:Execution failed for task ':sdk:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.*

If I create sample app and add Realm (last version) into the app gradle build file, it works. The issue is with the Realm used into the SDK module.

If you already had some similar issues and resolved them, or have an idea what is wrong, please share it. It would be appreciated.

Thanks in advance.

EDIT:

The fix was that I had to comment all the used deprecated methods, and then to compile. The compiler was showing all Realm objects as missing. Once the deprecated methods were commented out, the build succeeded.

like image 622
gpopov Avatar asked Dec 03 '22 14:12

gpopov


1 Answers

The main upgrade to Realm from olds verson to 5+ needs to change from:

realm.where(example.class)
    .findAllSorted("field")

To:

realm.where(example.class)
    .sort("field")
    .findAll();
like image 168
Fidan Bacaj Avatar answered Dec 06 '22 12:12

Fidan Bacaj