Android Room Persistence Library在库项目中不起作用 [英] Android Room Persistence Library not working inside library project

查看:182
本文介绍了Android Room Persistence Library在库项目中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android库,并且想在其中使用新的Android Room持久性库.但是,启动时出现此错误:

I'm developping an Android library, and want to use the new Android Room persistence library inside it. However, when launching I got this error :

Caused by: java.lang.RuntimeException: cannot find implementation for MyLibraryName.Database.QSDatabase. QSDatabase_Impl does not exist at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:90)

Caused by: java.lang.RuntimeException: cannot find implementation for MyLibraryName.Database.QSDatabase. QSDatabase_Impl does not exist at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:90)

这意味着 annotationProcessor 不会在编译过程中生成额外的代码.

which means that the annotationProcessor is not generating the extra code during compilation.

顺便说一句,当我将我的 @Database 代码放在应用模块中时,一切工作正常.

Btw, everything is working fine when I put my @Database code inside the app module.

我的gradle文件(库模块):

My gradle file (library module) :

apply plugin: 'com.android.library'
apply plugin: 'groovyx.android'

buildscript {
repositories {
    jcenter()
    maven { url 'https://maven.google.com' }
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.2'
    classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
}
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == 'com.android.support') {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion '25.3.0'
                }
            }
        }
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/main/groovy'] } }
}

dependencies {

// google Room persistence library
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"

compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})

// google location service
compile 'com.google.android.gms:play-services-location:10.2.4'

androidTestCompile 'junit:junit:4.12'
// Http
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
compile 'com.squareup.retrofit2:converter-scalars:2.1.0'

// groovy
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.4'

}

推荐答案

在kotlin项目中使用annotationProcessor时,可能会发生这种情况. 如果是这样,

This can happen when you use annotationProcessor in a kotlin project. if so, do these

apply plugin: 'kotlin-kapt'    

,并使用kapt代替annotationProcessor

这篇关于Android Room Persistence Library在库项目中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆