当前位置: 首页 > news >正文

BUG:Cannot find implementation for xxx. database. xxx. xxx_Impl does not exist

问题背景

        使用Jetpack Compose将数据存储在room本地数据库时,编译报错:

java. lang. RuntimeException: Cannot find implementation for com. example. androidproject. practice. roomdmeo. database. AppDatabase. AppDatabase_Impl does not exist

问题解决

        该错误主要是因为构建时 Room 生成的数据库实现类没有找到,通常是因为 Room 相关的注解处理器没有正确执行,或者构建时出现了问题。在StackOverflow中已经有大佬已经给出答案,链接为:

https://stackoverflow.com/questions/46665621/android-room-persistent-appdatabase-impl-does-not-exist

        主要原因就是org.jetbrains.kotlin.android的 版本问题,需要将其升级到"1.9.21"版本及以上。我也是按照这个思路去解决的,解决过程比好繁琐,就是不断的切换版本,看它能不能编译成功。我在这里也就直接贴出我的build.gradle.kts文件供大家参考。

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android") version "1.9.22"
    id("kotlin-kapt")  // 启用 kapt 插件,用于支持 Room 注解处理器
}



android {
    namespace = "com.example.androidproject"
    compileSdk = 36

    defaultConfig {
        applicationId = "com.example.androidproject"
        minSdk = 26
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
//        kotlinCompilerExtensionVersion = "1.5.1"
        kotlinCompilerExtensionVersion = "1.5.9"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {

    implementation("androidx.core:core-ktx:1.15.0")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
    implementation("androidx.activity:activity-compose:1.10.1")
    implementation(platform("androidx.compose:compose-bom:2025.03.01"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    implementation("androidx.constraintlayout:constraintlayout:2.2.1")

    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.2.1")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2025.03.01"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")


    // 页面导航依赖
    implementation("androidx.navigation:navigation-compose:2.8.9")  // 最新版本

    // 网络请求依赖
    implementation("com.squareup.retrofit2:retrofit:2.9.0") // Retrofit 核心库
    implementation("com.squareup.retrofit2:converter-gson:2.9.0") // Gson 转换器
    implementation("com.squareup.okhttp3:logging-interceptor:4.12.0") // 网络日志
    implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7") // Jetpack Compose ViewModel

    // room数据库
    implementation("androidx.room:room-runtime:2.6.1")
    implementation("androidx.room:room-ktx:2.6.1")   // 可选的 Kotlin 扩展
    kapt("androidx.room:room-compiler:2.6.1")  // 使用 kapt 代替 annotationProcessor
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id("com.android.application") version "8.2.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.22" apply false
}

http://www.dtcms.com/a/126581.html

相关文章:

  • 2024第十五届蓝桥杯大赛软件赛省赛Java大学B组 报数游戏 类斐波那契循环数 分布式队列 食堂 最优分组 星际旅行 LITS游戏 拼十字
  • 【力扣hot100题】(089)最长有效括号
  • 通用 Web 项目安全加固 Checklist(语言无关通用模板)
  • 【2025年认证杯数学中国数学建模网络挑战赛】A题 解题建模过程与模型代码(基于matlab)
  • ch07 部分题目思路
  • 量子指纹识别
  • 【数据结构】排序
  • golang通过STMP协议发送邮件功能详细操作
  • 化工行业电气智能化管理系统解决方案
  • CVE-2025-31486 Vite开发服务器任意文件读取漏洞复现
  • Pytorch实现基于FlowS-Unet的遥感图像建筑物变化检测方法
  • wireshark抓包,镜像端口,观察端口
  • protobuf的应用
  • 第三节:React 基础篇-React组件通信方案
  • JAVA Web_定义Servlet_1 欢迎考生
  • 客户案例 | 日事清×初心家居:多部门协作实现新品上架自动化
  • 分布式ID生成方案的深度解析与Java实现
  • Docker 常用命令指南
  • Python表达式入门指南:从基础到实践
  • leetcode-动态规划25
  • Java接口深度解析
  • B3647 【模板】Floyd
  • 深入 Redis 持久化:从原理到企业级应用的全景图
  • 音视频 五 看书的笔记 MediaCodec
  • 计算机网络 3-3 数据链路层(介质访问控制)
  • 第六章 进阶03 外包测试亮相
  • 第四十六篇 人力资源管理数据仓库架构设计与高阶实践
  • Nginx 命令大全:Linux 与 Windows 系统的全面解析
  • 《计算机名人堂》专栏介绍:先驱之路
  • c# BitMap的data是rgb格式还是bgr格式