Realm 0.88.2 example : Cannot resolve symbol

被刻印的时光 ゝ 提交于 2019-12-11 23:26:45

问题


I downloaded this : https://static.realm.io/downloads/java/realm-java-0.88.2.zip Then imported the "examples" folder inside Android Studio.

I can run examples but Android Studio cannot resolve symbols for Realm classes.

Is there something missing in this example project ? I want to enable completion.

Edit :
When I add "compile 'io.realm:realm-android:0.87.5'" to the build.gradle, this error occur :

[...]  
: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.  
[...]

回答1:


Since v0.88.0, you need to use the AAR configuration (using Gradle), by adding the Realm plugin to the application classpath and applying the plugin.

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

apply plugin: 'realm-android'



回答2:


The issue come from the main build.gradle.

Replace this :

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()
}
}

By something like this :

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()
    }
}



回答3:


Just try to include this in you dependencies inside your build.gradle file like:

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

It is the last version that is provided without a Gradle plugin.



来源:https://stackoverflow.com/questions/36285153/realm-0-88-2-example-cannot-resolve-symbol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!