realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
941 stars 57 forks source link

"runtimeapi" is not resolved #161

Closed grigorevp closed 3 years ago

grigorevp commented 3 years ago

Hi, I'm trying to use realm-kotlin in my project. I believe I've followed all the steps described and was able to see some Realm annotations, but runtimeapi was not resolved, thus RealmObject was not resolved either. Project wasn't built, getting something like this:

e: java.lang.AssertionError: Unbound symbols not allowed

Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@51380bec (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@62754e9 (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@4e45926e (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@734eb126 (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@72e875ae (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@23766be4 (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@588bd86e (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@7ef5db91 (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@5afd30b8 (NON-PUBLIC API)
...

I assumed there is something wrong with my project or other dependencies maybe, so I tried a kmm-sample from this repo. It won't build either but with following message:

e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/Expression.kt: (21, 17): Unresolved reference: runtimeapi
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/Expression.kt: (22, 17): Unresolved reference: runtimeapi
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/Expression.kt: (24, 20): Unresolved reference: RealmObject
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/Expression.kt: (28, 2): Unresolved reference: RealmModule
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/ExpressionRepository.kt: (28, 21): Type mismatch: inferred type is Entities but KClass<out RealmObject> was expected
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/ExpressionRepository.kt: (36, 39): Type mismatch: inferred type is Expression but RealmObject was expected
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/ExpressionRepository.kt: (44, 30): Type mismatch: inferred type is Expression but RealmObject was expected
e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/ExpressionRepository.kt: (48, 30): Type mismatch: inferred type is Expression but RealmObject was expected

Am I missing something?

nhachicha commented 3 years ago

Hi @grigorevp could you please share your project (or at least the various Gradle files) to double-check how are you importing the library?

grigorevp commented 3 years ago

Hi @nhachicha , thanks for quick response. Here is build.gradle.kts from my project:

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

val ktorVersion = "1.5.1"
val coroutinesVersion = "1.4.2-native-mt"
val serializationVersion = "1.0.1"
val reaktiveVersion = "1.1.20"
val klockVersion = "2.0.6"
val uuidVersion = "0.2.3"

plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization") version "1.4.30"
    id("com.android.library")
    id("kotlin-android-extensions")
}

buildscript {
    repositories {
        maven("http://oss.jfrog.org/artifactory/oss-snapshot-local")
    }
    dependencies {
        classpath("io.realm.kotlin:gradle-plugin:0.0.1-SNAPSHOT")
    }
}

apply(plugin = "realm-kotlin")

kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "Core"
            }
        }
    }
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-core:${ktorVersion}")
                implementation("io.ktor:ktor-client-serialization:${ktorVersion}")
                implementation("com.badoo.reaktive:reaktive:${reaktiveVersion}")
                implementation("com.badoo.reaktive:reaktive-annotations:${reaktiveVersion}")
                implementation("com.badoo.reaktive:coroutines-interop:${reaktiveVersion}")
                implementation("io.realm.kotlin:library:0.0.1-SNAPSHOT")
                implementation("com.soywiz.korlibs.klock:klock:${klockVersion}")
                implementation("com.benasher44:uuid:${uuidVersion}")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${serializationVersion}")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}") {
                    version {
                        strictly(coroutinesVersion)
                    }
                }
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.3.0")
                implementation("io.ktor:ktor-client-android:${ktorVersion}")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-ios:${ktorVersion}")
            }
        }
        val iosTest by getting
    }
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
    }
}

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val xcodeDir = File("../../../iOS/Project")
    //val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(xcodeDir)
    //into(targetDir)
}

tasks.getByName("build").dependsOn(packForXcode)

The one from your repo's kmm-sample was not modified by me and still is not building

rorbech commented 3 years ago

@grigorevp We eliminated the runtimeapi a week ago so this smells like something not using the latest sources or dependencies. We are still just publishing snapshot and will probably just do that until we also migrate to Maven Central.

Maybe check that dependencies are up to date with ./gradlew --refresh-dependencies and do a full clean build as the compiler plugin will not rebuild the model classes automatically if the plugin is updated.

grigorevp commented 3 years ago

@rorbech I've tried already but just made it once more. Nothing changes after refreshing and clean build. For me it's quite weird that even sample project won't build. On the one hand it drives me to an idea that I miss something basic, on the other hand gradle file seems fine

rorbech commented 3 years ago

@grigorevp Are you sure that you are using the latest source from the repository? The error

e: /Users/petr/Downloads/realm-kotlin-master/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/ExpressionRepository.kt: (28, 21): Type mismatch: inferred type is Entities but KClass<out RealmObject> was expected

does not look like it would be part of compilation of the latest code.

Related to your own project; it might be that the plugin is not re-downloaded when refreshing, as it is using internal mechanisms to pull the artifact. Do you mind trying to invalidate you cache if the issue persists?

grigorevp commented 3 years ago

@rorbech Well, I see that there was a commit yesterday while I used two-day old source. I've tried it out, but got this now:

> Task :shared:linkReleaseFrameworkIosArm64 FAILED
e: Compilation failed: null

 * Source files: 
 * Compiler version info: Konan: 1.4.30 / Kotlin: 1.4.30
 * Output kind: FRAMEWORK

e: java.lang.NullPointerException
        at org.jetbrains.kotlin.backend.konan.optimizations.Devirtualization$DevirtualizationAnalysis.calleeAt(Devirtualization.kt:267)
        at org.jetbrains.kotlin.backend.konan.optimizations.Devirtualization$DevirtualizationAnalysis.access$calleeAt(Devirtualization.kt:123)
        at org.jetbrains.kotlin.backend.konan.optimizations.Devirtualization$DevirtualizationAnalysis$ConstraintGraphBuilder.dfgNodeToConstraintNode(Devirtualization.kt:1192)
        at org.jetbrains.kotlin.backend.konan.optimizations.Devirtualization$DevirtualizationAnalysis$ConstraintGraphBuilder.edgeToConstraintNode(Devirtualization.kt:1042)
        at org.jetbrains.kotlin.backend.konan.optimizations.Devirtualization$DevirtualizationAnalysis$ConstraintGraphBuilder.access$edgeToConstraintNode(Devirtualization.kt:760)
...

I've also tried all these restarts, clean builds, invalidates etc.

Speaking about my own project, I've tried to invalidate & restart, but that didn't work for me. Are there any specific requirements to IDE or plugin versions? Maybe some other dependencies' versions? It seems that the problem is not project-related, but machine-related or me-related :|

nhachicha commented 3 years ago

@grigorevp this is a known limitation, Release build for Apple are not currently supported https://github.com/realm/realm-kotlin/issues/142

running debug flavour (example ./gradlew linkDebugFrameworkIosArm64 ) should work

rorbech commented 3 years ago

The original error yielding

e: java.lang.AssertionError: Unbound symbols not allowed

Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@51380bec (NON-PUBLIC API)
Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl@62754e9 (NON-PUBLIC API)

seemed to be cause by our compiler plugin triggering companion objects on some classes that shouldn't have it. Will be fixed by #155.

rorbech commented 3 years ago

Closing as #155 is merged. Please report it if you see it again.