Android RoomDatabase - 无法解析android.arch.persistence.room:compiler:1.0.0

时间:2018-01-19 12:48:34

标签: android gradle

Error:Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'.

Could not resolve android.arch.persistence.room:compiler:1.0.0. Required by: project :app

No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.
No cached version of android.arch.persistence.room:compiler:1.0.0 available for offline mode.

房间依赖

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

禁用离线模式和构建缓存。 Gradle 4.1版 Gradle项目文件

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

3 个答案:

答案 0 :(得分:2)

  

无法解析android.arch.persistence.room:compiler:1.0.0

要将其添加到项目中,请打开项目 build.gradle (Project Level) 文件,然后添加突出显示的行,如下所示:< / p>

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

<强>样本

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

    buildscript {

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

        }
    }

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

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

请阅读Adding Components to your Project

答案 1 :(得分:1)

您可能在Android Studio中使用离线模式。要停用离线模式

  1. 确保您的设备已连接到互联网。
  2. 转到文件 - &gt; 设置&amp;展开构建,执行,部署 - &gt; Gradle - &gt; UNCHECK离线工作 - &gt;的确定
  3. 转到文件 - &gt;点击使缓存无效/重新启动 - &gt; 无效&amp;重新启动
  4. 完成

答案 2 :(得分:0)

google() maven repo添加到您的项目中(两次出现):

buildscript {
  repositories {
    google()
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:3.1.1'
  }
}

allprojects {
  repositories {
    google()
    // Your other Maven Repos
  }
}