Получение ошибки «фактический объект BluetoothDeviceDbConstructor: RoomDatabaseConstructor<BluetoothDeviceDatabase>» не Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Получение ошибки «фактический объект BluetoothDeviceDbConstructor: RoomDatabaseConstructor<BluetoothDeviceDatabase>» не

Сообщение Anonymous »

Я строил базу данных, используя Roomdb в KMM, и получил эту ошибку, я неоднократно пытался изменить библиотечные версии, также все еще сталкиваясь с этой проблемой < /p>

Код: Выделить всё

[versions]
agp = "8.5.2"
android-compileSdk = "35"
android-minSdk = "24"
android-targetSdk = "35"
androidx-activityCompose = "1.9.3"
androidx-appcompat = "1.7.0"
androidx-constraintlayout = "2.2.0"
androidx-core-ktx = "1.15.0"
androidx-espresso-core = "3.6.1"
androidx-lifecycle = "2.8.3"
androidx-material = "1.12.0"
androidx-test-junit = "1.2.1"
compose-plugin = "1.7.0"
junit = "4.13.2"
kotlinx-coroutines = "1.9.0"
ktorClientContentNegotiation = "2.x.x"
ktorClientCore = "2.x.x"
navigationCompose = "2.8.0-alpha10"
kotlinSerialization = "1.7.3"
koin = "4.0.0"
ktor = "3.0.1"
coil3 = "3.0.0-rc02"
kotlin = "2.0.20"
ksp = "2.0.20-1.0.25"
room = "2.7.0-alpha07"
sqlite = "2.5.0-alpha07"

runtimeLivedata = "1.7.6"
media3CommonKtx = "1.5.1"
uiAndroid = "1.7.6"
bluetooth = "1.0.0-alpha02"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core-ktx" }
androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
androidx-material = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
androidx-lifecycle-viewmodel = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-viewmodel", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
kotlinx-coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }

jetbrains-compose-navigation = { group = "org.jetbrains.androidx.navigation", name = "navigation-compose", version.ref= "navigationCompose"}
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinSerialization" }

koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin" }
koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koin" }

ktor-client-content-negotiation-v2xx = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktorClientContentNegotiation" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-core-v2xx = { module = "io.ktor:ktor-client-core", version.ref = "ktorClientCore" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor"  }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-client-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" }

coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil3" }
coil-compose-core = { module = "io.coil-kt.coil3:coil-compose-core", version.ref = "coil3" }
coil-network-ktor2 = { module = "io.coil-kt.coil3:coil-network-ktor2", version.ref = "coil3" }
coil-network-ktor3 = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil3" }
coil-mp = { module = "io.coil-kt.coil3:coil", version.ref = "coil3" }

androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" }
androidx-runtime-livedata = { group = "androidx.compose.runtime", name = "runtime-livedata", version.ref = "runtimeLivedata" }
androidx-media3-common-ktx = { group = "androidx.media3", name = "media3-common-ktx", version.ref = "media3CommonKtx" }
androidx-ui-android = { group = "androidx.compose.ui", name = "ui-android", version.ref = "uiAndroid" }
androidx-bluetooth = { group = "androidx.bluetooth", name = "bluetooth", version.ref = "bluetooth" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
room = { id = "androidx.room", version.ref = "room"  }

[bundles]
ktor = [
"ktor-client-core",
"ktor-client-content-negotiation",
"ktor-client-auth",
"ktor-client-logging",
"ktor-serialization-kotlinx-json",
]
coil = [
"coil-compose",
"coil-compose-core",
"coil-network-ktor2",
"coil-network-ktor3",
"coil-mp"
]
< /code>
build.gradle.kts
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.jetbrains.kotlin.serialization)
alias(libs.plugins.ksp)
alias(libs.plugins.room)
id("dev.icerock.mobile.multiplatform-resources") version "0.23.0"
}

kotlin {
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
linkerOpts.add("-lsqlite3")
}
}
//    ksp {
//        arg("room.schemaLocation", "${projectDir}/schemas")
//    }
//   ksp { arg("room.schemaLocation","${projectDir}/schemas") }

//

//    tasks.withType().configureEach {
//        if (name != "kspCommonMainKotlinMetadata"  ) {
//            dependsOn("kspCommonMainKotlinMetadata")
//        }
//    }
sourceSets {

androidMain.dependencies {

implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
implementation(libs.ktor.client.okhttp)
implementation("io.ktor:ktor-serialization-gson:2.3.4")
implementation("dev.icerock.moko:resources:0.23.0")
}
commonMain.dependencies {

implementation("androidx.core:core-ktx:1.15.0")
implementation("dev.icerock.moko:resources:0.23.0")
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
//    implementation("io.ktor:ktor-serialization-gson:2.2.0")
//   implementation("com.google.code.gson:gson:2.10.1")
implementation(libs.ktor.client.core.v2xx)
implementation(libs.ktor.client.content.negotiation.v2xx)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.jetbrains.compose.navigation)
implementation(libs.kotlinx.serialization.json)
implementation(libs.androidx.room.runtime)
implementation(libs.sqlite.bundled)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
api(libs.koin.core)
implementation(libs.bundles.ktor)
implementation(libs.bundles.coil)
// implementation("io.github.microutils:kotlin-logging-jvm:2.1.21")
implementation("com.github.skydoves:cloudy:0.2.3")

}

nativeMain.dependencies {
implementation(libs.ktor.client.darwin)
implementation(compose.ui)

}

dependencies {
ksp(libs.androidx.room.compiler)
}
}
}

android {
namespace = "in.janitri.hospitals.janitriforhospitals"
compileSdk = libs.versions.android.compileSdk.get().toInt()

defaultConfig {
applicationId = "in.janitri.hospitals.janitriforhospitals"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
}

}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
//  isCoreLibraryDesugaringEnabled=true
}

}

dependencies {

add("kspAndroid", libs.androidx.room.compiler)
add("kspIosSimulatorArm64", libs.androidx.room.compiler)
add("kspIosX64", libs.androidx.room.compiler)
add("kspIosArm64", libs.androidx.room.compiler)
add("kspCommonMainMetadata",  libs.androidx.room.compiler)

implementation(libs.androidx.runtime.livedata)
implementation(libs.androidx.media3.common.ktx)
implementation(libs.androidx.ui.android)
implementation(libs.androidx.bluetooth)
debugImplementation(compose.uiTooling)
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")

}
room {
schemaDirectory("$projectDir/schemas")
}

//multiplatformResources {
//    multiplatformResourcesPackage = "in.janitri.hospitals.janitriforhospitals"
//}
< /code>
И это модульный уровень build.gradle.kts < /p>
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.room) apply false
}
buildscript {
repositories {
flatDir {
dirs("libs")
}
mavenCentral()
}

}
import androidx.room.RoomDatabaseConstructor
@Suppress("NO_ACTUAL_FOR_EXPECT")
expect object BluetoothDeviceDbConstructor :RoomDatabaseConstructor{
override fun initialize(): BluetoothDeviceDatabase
}
@Database(entities = [BluetoothTb::class],version=1)
@ConstructedBy(BluetoothDeviceDbConstructor::class)
abstract class BluetoothDeviceDatabase(): RoomDatabase(){
abstract val bluetoothDao: BluetoothDao

companion object{
val BLUETOOTH_DB="bluetooth_device_db"
}
}.

Я пытался добавить и снять различные плагины, а также вносить изменения в код, но ничего не работает. в основном дает такую ​​ошибку < /p>
public actual object BluetoothDeviceDbConstructor : RoomDatabaseConstructor
{
actual override fun initialize(): BluetoothDeviceDatabase =
`in`.janitri.hospitals.janitriforhospitals.bluetooth.`data`.BluetoothDeviceDatabase_Impl()
}
'

actual object BluetoothDeviceDbConstructor : RoomDatabaseConstructor' has no corresponding expected declaration
BluetoothDeviceDbConstructor: expect and corresponding actual are declared in the same module 'actual fun initialize(): BluetoothDeviceDatabase' has no corresponding expected declaration
< /code>
при составлении кода он автоматически создает фактический объект в метаданных, даже если я не пишу линию подавления в ожидаемом конструкторе и создаю фактический конструктор для Android и iOS Также я получаю ту же проблему


Подробнее здесь: https://stackoverflow.com/questions/793 ... econstruct
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»