Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues upgrading from Realm-Java-Android to Realm-Kotlin-Android #1859

Open
DrEdHepler opened this issue Feb 7, 2025 · 1 comment

Comments

@DrEdHepler
Copy link

I have a project that is a couple years old, that uses Realm (local database) written in Java for Android.

I recently wanted to add some features, but wanted to update it to use a more current version of Android Studio, etc. In the process, I had some problems, and it seems that the newest version of Realm is the Kotlin version. So I used the Android Studio "tool" to convert the application from Java to Kotlin and tried to compile.

I got everything to compile, except for the accesses to Realm. All Realm keywords are flagged as "Unresolved reference". I suspect that I am not configuring something properly.

Here is the project level build.gradle:

buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven  { url "https://jitpack.io" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.8.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.20"
        classpath "io.realm.kotlin:io.realm.kotlin.gradle.plugin:3.0.0"
        classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id("io.realm.kotlin") version "3.0.0"
}

allprojects {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

apply plugin:  "io.realm.kotlin"

task clean(type: Delete) {
    delete rootProject
}

and the app build.gradle:

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("kotlin-android")
    id("kotlin-kapt")
    id("io.realm.kotlin") version "3.0.0"
    id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

//apply plugin: "realm-android"
apply plugin: "io.realm.kotlin"

android {
    namespace 'com.VLSI_Concepts.mymodelrockets'
    compileSdk 34


    defaultConfig {
        applicationId "com.VLSI_Concepts.mymodelrockets"
        minSdkVersion 34
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        buildConfig = true
        compose = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.6"
    }
    kotlinOptions {
        jvmTarget = '17'
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.7.0'
//.    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
    implementation 'com.google.android.gms:play-services-maps:19.0.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.2.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'

    // timber
    implementation 'com.jakewharton.timber:timber:5.0.1'

    // For Nordic version of BLE Library
    implementation 'no.nordicsemi.android:ble:2.9.0'
    implementation 'no.nordicsemi.android:ble-livedata:2.9.0'
    implementation 'no.nordicsemi.android.support.v18:scanner:1.6.0'

    // Realm adapter
    implementation 'io.realm.kotlin:gradle-plugin:3.0.0'
    implementation 'io.realm.kotlin:library-base:1.16.0'

    // Image picker
    implementation 'com.github.dhaval2404:imagepicker:1.8'
}

It's almost as if the Realm "library" is not being included in the build... All of the "red" characters in the image below are "Unresolved references". Any suggestions on what I'm doing wrong?? Thanks!

Image

@promanowicz
Copy link

There is still java realm.
https://github.com/realm/realm-java
Kotlin classes have different packages
eg: io.realm.kotlin.types.RealmObject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants