领域0.88.2示例:无法解析符号

时间:2016-03-29 13:05:31

标签: android realm

我下载了这个: https://static.realm.io/downloads/java/realm-java-0.88.2.zip 然后导入"示例" Android Studio中的文件夹。

我可以运行示例,但Android Studio无法解析Realm类的符号。

此示例项目中是否缺少某些内容?我想启用完成。

enter image description here

编辑:
当我添加"编译' io.realm:realm-android:0.87.5'"到build.gradle, 发生此错误:

[...]  
:introExample:generateDebugSources UP-TO-DATE
:introExample:compileDebugJavaWithJavac
Note: Processing class Cat
Note: Processing class Dog
Note: Processing class Person
Note: Creating DefaultRealmModule

:introExample:compileDebugNdk UP-TO-DATE
:introExample:compileDebugSources
:introExample:transformClassesWithRealmTransformerForDebug
:introExample:transformClassesWithDexForDebug

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lio/realm/RealmCache$Callback;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)



 FAILED

FAILURE: Build failed with an exception.  
[...]

3 个答案:

答案 0 :(得分:2)

从v0.88.0开始,你需要使用AAR配置(使用Gradle),将Realm插件添加到应用程序类路径并应用插件。

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

apply plugin: 'realm-android'

答案 1 :(得分:1)

尝试将此包含在build.gradle文件中的依赖项中,如:

compile 'io.realm:realm-android:0.87.5'

这是没有Gradle插件时提供的最后一个版本。

答案 2 :(得分:1)

问题来自main build.gradle。

替换它:

allprojects {
    def currentVersion = file("${rootDir}/../version.txt").text.trim()

    buildscript {
        repositories {
            mavenLocal()
            jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
        classpath 'com.novoda:gradle-android-command-plugin:1.5.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath "io.realm:realm-gradle-plugin:${currentVersion}"
    }
}

group = 'io.realm'
version = currentVersion

repositories {
    mavenLocal()
    jcenter()
}
}

通过以下方式:

buildscript {
def currentVersion = file("${rootDir}/../version.txt").text.trim();
repositories {
    mavenLocal()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
    classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
    classpath 'com.novoda:gradle-android-command-plugin:1.5.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
allprojects {
    group = 'io.realm'
    version = "0.88.2"

    repositories {
        mavenLocal()
        jcenter()
    }
}