You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Google仓库后仍无法找到Android Room Gradle插件的问题排查求助

添加Google仓库后仍无法找到Android Room Gradle插件的问题排查求助

我正在做一个Kotlin项目,想用到Room库来操作SQLite。按照官方指引,我在build.gradle.kts的plugins区块里添加了id("androidx.room") version "2.7.2"。因为这个插件在Google的Maven仓库里,我也在repositories区块里加了google(),甚至试过直接写完整的仓库地址maven { url = "https://maven.google.com/" },但还是遇到了下面的错误:

Plugin [id: 'androidx.room', version: '2.7.2'] was not found in any of the following sources:

  • Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
  • Included Builds (No included builds contain this plugin)
  • Plugin Repositories (could not resolve plugin artifact 'androidx.room:androidx.room.gradle.plugin:2.7.2')
    Searched in the following repositories:
    Gradle Central Plugin Repository

我有几个疑问:

  • “Included Builds”指的是Google仓库吗?
  • 是不是我添加Google仓库的方式不对,导致它没被搜索到?
  • “Gradle Central Plugin Repository”和Maven Central是同一个东西或者包含关系吗?

下面是我最初的build.gradle.kts完整代码:

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
    maven { url = "https://maven.google.com/" }
}

plugins {
    // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
    kotlin("jvm") version "2.2.0"
    id("androidx.room") version "2.7.2"
    // Apply the application plugin to add support for building a CLI application in Java.
    application
}

dependencies {
    // Use the Kotlin JUnit 5 integration.
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
    // Use the JUnit 5 integration.
    testImplementation(libs.junit.jupiter.engine)
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")

    // This dependency is used by the application.
    implementation(libs.guava)
    //implementation("io.klogging:klogging-jvm:0.11.4")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
}

// Apply a specific Java toolchain to ease working on different environments.
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

application {
    // Define the main class for the application.
    mainClass = "MainKt"
}

tasks.named<Test>("test") {
    // Use JUnit Platform for unit tests.
    useJUnitPlatform()
}

编辑补充:
不知道为什么,只有Room插件找不到,但仓库里的Room库是能正常检索到的——我手动添加依赖后项目就能正常工作了。这是我现在可用的build文件:

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
    google()
}

plugins {
    // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
    kotlin("jvm") version "2.2.0"
    id("com.google.devtools.ksp") version "2.2.0-2.0.2"
    // Apply the application plugin to add support for building a CLI application in Java.
    application
}

dependencies {
    val roomv = "2.7.2"
    implementation("androidx.room:room-runtime:$roomv")
    ksp("androidx.room:room-compiler:$roomv")

    // Use the Kotlin JUnit 5 integration.
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
    // Use the JUnit 5 integration.
    testImplementation(libs.junit.jupiter.engine)
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")

    // This dependency is used by the application.
    implementation(libs.guava)
    //implementation("io.klogging:klogging-jvm:0.11.4")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
}

// Apply a specific Java toolchain to ease working on different environments.
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

application {
    // Define the main class for the application.
    mainClass = "MainKt"
}

tasks.named<Test>("test") {
    // Use JUnit Platform for unit tests.
    useJUnitPlatform()
}

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 13:23:02