0

I'm new here, grateful to meet you all here. I have an error like this based on my Logcat.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voidcreativestation.toko/com.voidcreativestation.toko.view.MainActivity}: java.lang.RuntimeException: Cannot find implementation for com.voidcreativestation.toko.room.StockQuantityRoom. StockQuantityRoom_Impl does not exist
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
                                                                                                        at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                                        at android.os.Looper.loop(Looper.java:164)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6944)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
                                                                                                    Caused by: java.lang.RuntimeException: Cannot find implementation for com.voidcreativestation.toko.room.StockQuantityRoom. StockQuantityRoom_Impl does not exist
                                                                                                        at androidx.room.Room.getGeneratedImplementation(Room.kt:58)
                                                                                                        at androidx.room.RoomDatabase$Builder.build(RoomDatabase.kt:1356)
                                                                                                        at com.voidcreativestation.toko.room.StockQuantityRoom$Companion.getDatabase(StockQuantityRoom.kt:64)
                                                                                                        at com.voidcreativestation.toko.TokoApplication$database$2.invoke(TokoApplication.kt:19)
                                                                                                        at com.voidcreativestation.toko.TokoApplication$database$2.invoke(TokoApplication.kt:19)
                                                                                                        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
                                                                                                        at com.voidcreativestation.toko.TokoApplication.getDatabase(TokoApplication.kt:19)
                                                                                                        at com.voidcreativestation.toko.TokoApplication$repository$2.invoke(TokoApplication.kt:20)
                                                                                                        at com.voidcreativestation.toko.TokoApplication$repository$2.invoke(TokoApplication.kt:20)
                                                                                                        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
                                                                                                        at com.voidcreativestation.toko.TokoApplication.getRepository(TokoApplication.kt:20)
                                                                                                        at com.voidcreativestation.toko.view.MainActivity$stockQuantityViewModel$2.invoke(MainActivity.kt:18)
                                                                                                        at com.voidcreativestation.toko.view.MainActivity$stockQuantityViewModel$2.invoke(MainActivity.kt:17)
                                                                                                        at androidx.lifecycle.ViewModelLazy.getValue(ViewModelLazy.kt:47)
                                                                                                        at androidx.lifecycle.ViewModelLazy.getValue(ViewModelLazy.kt:35)
                                                                                                        at com.voidcreativestation.toko.view.MainActivity.getStockQuantityViewModel(MainActivity.kt:17)
                                                                                                        at com.voidcreativestation.toko.view.MainActivity.onCreate(MainActivity.kt:30)
                                                                                                        at android.app.Activity.performCreate(Activity.java:7183)
                                                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
                                                                                                        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                                                        at android.os.Looper.loop(Looper.java:164) 
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6944) 
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

and here's my gradle if you need it

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

android {
    namespace 'com.voidcreativestation.toko'
    compileSdk 33

    defaultConfig {
        applicationId "com.voidcreativestation.toko"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    kotlin {
        jvmToolchain(8)
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    packagingOptions {
        exclude 'META-INF/atomicfu.kotlin_module'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
    implementation "androidx.activity:activity-ktx:$rootProject.activityVersion"

    // Dependencies for working with Architecture components
    // You'll probably have to update the version numbers in build.gradle (Project)

    // Room components
    implementation "androidx.room:room-ktx:$rootProject.roomVersion"
    kapt "androidx.room:room-compiler:$rootProject.roomVersion"
    androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
    implementation "androidx.room:room-runtime:$rootProject.roomVersion" //StackOverflow attempt 1

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion"

    // Kotlin components
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"

    // UI
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
    implementation "com.google.android.material:material:$rootProject.materialVersion"

    // Testing
    testImplementation "junit:junit:$rootProject.junitVersion"
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
    androidTestImplementation ("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"

}

This is my version in rootProject

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.5.31'
}
plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
}

ext {
    activityVersion = '1.7.2'
    appCompatVersion = '1.6.1'
    constraintLayoutVersion = '2.1.4'
    coreTestingVersion = '2.2.0'
    coroutines = '1.7.1'
    lifecycleVersion = '2.6.1'
    materialVersion = '1.9.0'
    roomVersion = '2.5.1'
    // testing
    junitVersion = '4.13.2'
    espressoVersion = '3.5.1'
    androidxJunitVersion = '1.1.5'
}

And this is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:name=".TokoApplication"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Toko"
        tools:targetApi="31">
        <activity
            android:name=".view.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

and the codes is all HERE in public gist github

All I realize is from this forum, I check the generated and still not the same in the example, this is from my Reference and here's mine, Database_Impl not generated

My tries:

  • Using kapt and yes I use the id 'kotlin-kapt' for plugin or the same with apply plugin: 'kotlin-kapt'
  • ChatGPT asked me to remove .allowMainThreadQueries() in StockQuantityRoom, still the same
  • ChatGPT also recommended me to put the annotation @JvmStatic above fun getDatabase, Still no clue
  • Commented the @WorkerThread in StockQuantityRepository but to no avail
  • Use the same version as the reference (https://developer.android.com/codelabs/android-room-with-a-view-kotlin) but no progress
  • I double-triple check everything like names, var, and I all wrote there and the error still persist
  • Every time I tried, I always Clean project and Rebuild project
  • Invalidate Caches every time if there's no progress with Clean project and Rebuild project
  • Create everything from start again based on Reference and my database still error with the same code as above as this is my third attempt.
  • add implementation "androidx.room:room-runtime:$rootProject.roomVersion" in the gradle, still error
  • open the IDE in administrator mode, clean and rebuild, still the same
  • I add (Dispatchers.IO) after scope.launch in StockQuantityRoom.kt in my Gist(https://gist.github.com/KeiLazu/10540d564a51f574e0de2ccf1223311d) but still the error doesn't go away

Thank you in advance

K La
  • 1
  • 2
  • You forgot to add `room-runtime` dependency. – Masoud Karimi Jun 13 '23 at 07:39
  • @MasoudKarimi After I tried adding the `implementation "androidx.room:room-runtime:$rootProject.roomVersion"` and run, also clean project and rebuild project, also with invalidate caches, the error still persist. I'll update that to my post – K La Jun 13 '23 at 08:11
  • @KLa have you declared your ``TokoApplication `` class in ``AndroidManifest.xml`` ? – Anubis94 Jun 13 '23 at 13:33
  • @Anubis94 Yes, I already declared my `.TokoApplication` class in `AndroidManifest.xml`, I'll put my `AndroidManifest.xml` in post too – K La Jun 14 '23 at 01:21
  • @KLa try with ``2.4.3`` or ``2.5.0`` version of room database – Anubis94 Jun 14 '23 at 09:04
  • @Anubis94 I never tried to downgrade only the room version, the StockQuantityRoom_Impl has been implemented, thank you, it's fixed now. – K La Jun 15 '23 at 01:41
  • @KLa after downgrade? or did you find another solution? – Anubis94 Jun 15 '23 at 12:45
  • @Anubis94 Your solution is right, I change the version of room from `2.5.1` to `2.4.3` and it works – K La Jun 16 '23 at 01:37

1 Answers1

0

Here u have a post, where I think you could solve the same problem

Android room persistent: AppDatabase_Impl does not exist

  • Hello, I tried to change back to `annotationProcessor` to `kapt` back and forth but still error. And I already used the `implementation "androidx.room:room-ktx:$room_version"` and `kapt "androidx.room:room-compiler:$room_version"` in the build.gradle above – K La Jun 14 '23 at 01:32