领域注释处理器错误没有提升

问题描述 投票:0回答:2

我一直得到关于Realm库的注释处理器的错误无法加载,我错过了什么?我在哪里添加或者我应该怎么做?

这是我得到的错误:

“现在必须显式声明注释处理器。发现以下对编译类路径的依赖包含注释处理器。请将它们添加到annotationProcessor配置中.-- realm-android-0.82.1.jar(io.realm:realm-android: 0.82.1)”

请帮忙。

App.Gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.version.crt.myapplication"
    minSdkVersion 22
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'

implementation 'io.realm:realm-android:0.82.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Project.gradle

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'


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

allprojects {
repositories {
    google()
    jcenter()
}
}

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

请协助!

java android realm
2个回答
2
投票

按照realm docs中提到的说明进行操作

步骤1:将类路径依赖项添加到项目级build.gradle文件。 (你称之为Project gradle)

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

第2步:将realm-android插件应用到应用程序级build.gradle文件的顶部。 (你称之为App gradle)

apply plugin: 'realm-android'
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.version.crt.myapplication"
    minSdkVersion 22
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

1
投票

下面加两行

implementation 'io.realm:realm-android:0.82.1'
annotationProcessor 'io.realm:realm-android:0.82.1'

而不只是一行

implementation 'io.realm:realm-android:0.82.1'

应该解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.