2016-04-23 4 views
0

Я обновляемой от Realm 0.87.2 до 0.89.0, и я получаю сообщение об ошибке:Обновление для Realm 0.89.0 (от 0.87.2)

RealmClass annotated object must implement RealmModel or derive from RealmObject

для классов, которые делают, по сути, продлить RealmObject.

На основании инструкции на веб-сайте (для установки 0.89.0), я добавил зависимость плагин для проекта уровень build.gradle файла:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.0.0' 
     classpath 'io.realm:realm-gradle-plugin:0.89.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     maven { 
      url "https://jitpack.io" 
     } 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

Добавлена ​​«применить плагин» для файл уровень приложения build.gradle (и удаляются устаревшая зависимость компиляции):

apply plugin: 'com.android.application' 
apply plugin: 'realm-android' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     applicationId "com.winterberrysoftware.luthierlab" 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    packagingOptions { 
     exclude 'LICENSE.txt' 
    } 
} 

repositories { 
    maven { 
     // Stetho-Realm browser 
     url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' 
    } 
} 

ext { 
    supportLibVersion = "23.3.0" 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

    androidTestCompile "com.android.support:support-annotations:$supportLibVersion" 

    // Android JUnit Runner 
    androidTestCompile 'com.android.support.test:runner:0.4.1' 

    // JUnit4 Rules 
    androidTestCompile 'com.android.support.test:rules:0.4.1' 

    // Espresso core 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource 
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') { 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude module: 'recyclerview-v7' 
    } 

    testCompile 'junit:junit:4.12' 

    compile "com.android.support:appcompat-v7:$supportLibVersion" 
    compile "com.android.support:design:$supportLibVersion" 
    compile "com.android.support:support-v4:$supportLibVersion" 
    compile "com.android.support:recyclerview-v7:$supportLibVersion" 

    // Realm-RecyclerView 
    // SuperSLiM should automatically load from github when realm-recyclerview 
    // loads. For some reason, the revision tag in the realm-recyclerciew 
    // package is ed0ba4b4d2 and github won't find it with that tag. 
    // If I lop off the trailing '2' and load it explicitly, everything works 
    // fine. 
    compile 'com.github.TonicArtos:SuperSLiM:ed0ba4b4' 
    compile 'com.github.thorbenprimke:realm-recyclerview:0.9.12' 

    // Stetho-Realm browser (for debug only) 
    debugCompile 'com.facebook.stetho:stetho:1.2.0' 
    debugCompile 'com.uphyca:stetho_realm:0.8.0' 
} 

Вот один из моих классов, который расширяет RealmObject (и вызывает паразитную ошибку):

package com.winterberrysoftware.luthierlab.model; 

import io.realm.RealmObject; 
import io.realm.annotations.PrimaryKey; 

/** 
* The RealmProject class manages a Realm object with the details 
* of a particular project. 
*/ 
public class RealmProject extends RealmObject { 

    @PrimaryKey 
    private String name; 

    private RealmShape realmShape; 

    public RealmProject() { 
     // required no-argument public constructor 
    } 

    public RealmProject(String name, RealmShape realmShape) { 
     this.name = name; 
     this.realmShape = realmShape; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public RealmShape getRealmShape() { 
     return realmShape; 
    } 

    public void setRealmShape(RealmShape realmShape) { 
     this.realmShape = realmShape; 
    } 
} 

Вот Gradle журнал, показывающий ошибку:

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug] 
:app:clean 
... lines omitted ... 
:app:generateDebugAndroidTestSources 
:app:compileDebugJavaWithJavac 
C:\Users\Clo\Documents\Java Projects\AndroidStudioProjects\LuthierLab\app\src\main\java\com\winterberrysoftware\luthierlab\model\RealmProject.java 
Error:(15, 8) error: A RealmClass annotated object must implement RealmModel or derive from RealmObject 
Note: Processing class RealmProject 
C:\Users\Clo\Documents\Java Projects\AndroidStudioProjects\LuthierLab\app\src\main\java\com\winterberrysoftware\luthierlab\model\RealmShape.java 
Error:(14, 8) error: A RealmClass annotated object must implement RealmModel or derive from RealmObject 
Note: Processing class RealmShape 
Note: Creating DefaultRealmModule 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 
Information:BUILD FAILED 
Information:Total time: 5.15 secs 
Information:3 errors 
Information:0 warnings 
Information:See complete output in console 

вещи я пытался:

  • Android Студия Строить команды: Make Project, Clean Project, Rebuild Project
  • .gradlew чистый (для каждого веб-сайта)

ответ

1

Я понял. Я использую realm-recycleview (github for realm-recyclerview), и он тянул в более раннюю версию Realm (0.87.2). Таким образом, у моего проекта были две версии Realm: 0.87.2 и 0.89.0, а старшая версия загружалась первой.

Я ссылался на realm-recyclerviewer 0.9.12, на сайте github появилась более новая версия realm-recyclerview (0.9.14). Проблема с переходом на новую версию.

Смежные вопросы