簡體   English   中英

從0.87.2更新到Realm 0.89.0

[英]Updating to Realm 0.89.0 (from 0.87.2)

我正在從Realm 0.87.2升級到0.89.0,並且收到錯誤消息:

帶RealmClass注釋的對象必須實現RealmModel或從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插件”(並刪除了過時的編譯依賴項):

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 Studio Build命令:制作項目,清理項目,重建項目
  • .gradlew clean(根據網站的說明)

我想到了。 我正在使用realm-recycleview( realm-recyclerview的github ),並且它引入了Realm的早期版本(0.87.2)。 因此,我的項目實際上具有Realm的兩個版本:0.87.2和0.89.0,並且首先加載了舊版本。

我指的是realm-recyclerviewer 0.9.12,github站點上有更新的realm-recyclerview(0.9.14)版本。 切換到較新的版本可以解決此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM