Existing Android Java project to KMM, Unresolved reference to everything

I was given a task to convert an existing android app so it works on iOS using kotlin multiplatform. I will mention that I am very green in this area and not experienced at all, so I would highly appreciate guidance. After creating the shared module and fidgeting with the build.gradle files I finally got the project to build, however once I moved a java file from androidApp module to the shared module and converted it to a kotlin file, every import and further code throws an unresolved reference error. For example I have this file that was originaly in java:

import android.content.Intent;
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class FbInstanceIdService extends FirebaseInstanceIdService{

    public static final String TAG = "FirebaseID";
    public static final String TOKEN_BROADCAST = "tokenbroadcast";


    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.

        getApplicationContext().sendBroadcast(new Intent(TOKEN_BROADCAST));
        storeToken(refreshedToken);
    }

    private void storeToken(String token){
        SharedPreferencesManager.getInstance((getApplicationContext())).storeFirebaseToken(token);
    }
}

This is the same code converted to kotlin:

package eu.tinysolutions.tinyprocas

import android.content.Intent
import android.util.Log
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.iid.FirebaseInstanceIdService


class FbInstanceIdService : FirebaseInstanceIdService() {
    fun onTokenRefresh() {
        // Get updated InstanceID token.
        val refreshedToken: String = FirebaseInstanceId.getInstance().getToken()
        android.util.Log.d(
            TAG,
            "Refreshed token: $refreshedToken"
        )

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        getApplicationContext().sendBroadcast(Intent(TOKEN_BROADCAST))
        storeToken(refreshedToken)
    }

    private fun storeToken(token: String) {
        SharedPreferencesManager.getInstance(getApplicationContext()).storeFirebaseToken(token)
    }

    companion object {
        const val TAG = "FirebaseID"
        const val TOKEN_BROADCAST = "tokenbroadcast"
    }
}

I got errors like these:
Unresolved reference: content
Unresolved reference: util
Unresolved reference: FirebaseInstanceId
Unresolved reference: FirebaseInstanceIdService
Unresolved reference: getApplicationContext
and so on…

There are a ton more files but everywhere the errors remain similar.

I mostly tried changing the build.gradle files, however no errors were solved. I will post them in case they do help solve the problem.

Project level build.gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
    
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:8.1.4')
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0"

        classpath 'com.google.gms:google-services:4.4.1'
    }
}

plugins {
    // Declare the Kotlin Multiplatform plugin with a specific version and set apply false
    id 'org.jetbrains.kotlin.multiplatform' version '1.9.0' apply false
    id 'com.android.application' version '8.1.4' apply false
    id 'com.android.library' version '8.1.4' apply false
    id("com.google.gms.google-services") version "4.4.1" apply false

}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

androidApp build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdk 27
    defaultConfig {
        applicationId "changedID"
        minSdkVersion 26
        targetSdkVersion 27
        versionCode 11
        versionName "1.11"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    applicationVariants.all { variant ->
        variant.resValue "string", "versionName", variant.versionName
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    namespace 'changedNamespace'
}

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.ms-square:expandableTextView:0.1.4'
    implementation project(':shared')
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
}

apply plugin: 'com.google.gms.google-services'

shared module build.gradle.kts file:

plugins {
    //alias(libs.plugins.kotlinMultiplatform)
    //alias(libs.plugins.androidLibrary)
    //alias(libs.plugins.androidApplication)
    id("org.jetbrains.kotlin.multiplatform")
    id("com.android.application")
    id("com.google.gms.google-services")
}

repositories {
    maven(url = "https://jitpack.io")
}


kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
            isStatic = true
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
                implementation(project(":shared"))
                implementation ("com.android.support:appcompat-v7:27.1.1")
                implementation ("com.android.support.constraint:constraint-layout:1.1.1")
                implementation ("com.android.support:support-v4:27.1.1")
                implementation ("com.google.firebase:firebase-messaging:11.8.0")
                implementation ("com.android.support:support-v4:27.1.1")
                implementation ("com.android.support:design:27.1.1")
                implementation ("com.android.volley:volley:1.1.0")
                implementation ("com.ms-square:expandableTextView:0.1.4")
                implementation ("com.github.PhilJay:MPAndroidChart:v3.0.3")
            }
        }
        val androidMain by getting{
            dependencies{
                implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
                implementation(project(":shared"))
                implementation ("com.android.support:appcompat-v7:27.1.1")
                implementation ("com.android.support.constraint:constraint-layout:1.1.1")
                implementation ("com.android.support:support-v4:27.1.1")
                implementation ("com.google.firebase:firebase-messaging:11.8.0")
                implementation ("com.android.support:support-v4:27.1.1")
                implementation ("com.android.support:design:27.1.1")
                implementation ("com.android.volley:volley:1.1.0")
                implementation ("com.ms-square:expandableTextView:0.1.4")
                implementation ("com.github.PhilJay:MPAndroidChart:v3.0.3")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }

        // Specific platform configurations
        val iosX64Main by getting {
            dependsOn(commonMain)
        }
        val iosArm64Main by getting {
            dependsOn(commonMain)
        }
        val iosSimulatorArm64Main by getting {
            dependsOn(commonMain)
        }
    }
}

android {
    namespace = "changedNamespace"
    compileSdk = 27
    defaultConfig {
        minSdk = 26
        applicationId = "changedID"
        versionCode = 11
        versionName = "1.11"
        targetSdk = 27
    }
}

New contributor

cheese is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật