java - 无法解析 Room 依赖项

标签 java android gradle android-gradle-plugin

我想将以下依赖项添加到我的项目中:

1.compile "android.arch.persistence.room:runtime:1.0.0"
2.annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

但我的项目无法解析“:app@debug/compileClasspath”的依赖关系:无法解析 android.arch.persistence.room:runtime:1.0.0。 以下文本显示我的 build.gradle

apply plugin: 'com.android.application'

android {
 compileSdkVersion 27
 defaultConfig {
     applicationId "com.smm.room"
     minSdkVersion 17
     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.2'
 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'

 compile "android.arch.persistence.room:runtime:1.0.0"
 annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}

最佳答案

将两者都更新到 1.1.1 版本,例如:

implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

试试下面的代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.smm.room"
        minSdkVersion 17
        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.2'
    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'

    implementation "android.arch.persistence.room:runtime:1.1.1"
    annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
}

你的项目宏伟应该是这样的:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

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

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

关于java - 无法解析 Room 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961309/

相关文章:

Java 应用程序自动调整大小以适应屏幕分辨率

java - 我应该在 Spring 和 Android 中使用一种 Java 模型表示吗?

android - 警报管理器可靠性

android - 如何在 Hockeyapp 上将 Nevercode 构建从一个应用程序迁移到另一个应用程序?

android - 如何在Eclipse中打开Gradle项目?

Java CUP资源,还用着吗?

java - 如何从字符串中提取括号数据

java - Android Studio Gradle“文件 google-services.json 缺少模块根目录。没有它,Google 服务插件无法运行。”

java - gradle init 在转换一个简单的 maven 项目时抛出 CycleDetectedException

gradle 日志记录仅在我使用生命周期时显示消息