添加Room编译器后找不到GlideApp

时间:2018-08-02 12:25:46

标签: android android-room android-glide

将房间组件添加到gradle配置文件后,

编译项目失败,错误为“找不到符号类GlideApp”。如果注释掉“注释处理器” android.arch.persistence.room:compiler:$room_version”,则项目编译不会出错。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.otpuskarche.onleave"
        minSdkVersion 24
        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 {
    def room_version = "1.1.1"
    def archLifecycleVersion = '1.1.1'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.google.code.gson:gson:2.8.3'
    implementation 'com.android.support:support-v4:27.1.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'com.android.support:gridlayout-v7:27.1.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'

    // Room components
    implementation "android.arch.persistence.room:runtime:$room_version"
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"
    androidTestImplementation "android.arch.persistence.room:testing:$room_version"

    // Lifecycle components
    implementation "android.arch.lifecycle:extensions:$archLifecycleVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$archLifecycleVersion"

    testImplementation 'junit:junit:4.12'
}

3 个答案:

答案 0 :(得分:2)

问题出在房间上。未设置架构导出目录。由于错误出现在日志底部,因此构建日志使我感到困惑。

对真实问题的引用-room-schema-export

答案 1 :(得分:0)

您需要添加注释处理器依赖项:

annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'

您还需要添加一个AppGlideModule。有关详细信息,请参见generated API documentation

答案 2 :(得分:0)

创建像这样的呼叫

@GlideModule
public final class GlideLoader extends AppGlideModule{


 }

然后构建项目。然后您将通过GlideApp访问glide。