moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Expected object 'MR' has no actual declaration in module MyApplication.shared.iosArm64Main for Native

Open wangzhigang1112 opened this issue 2 years ago • 11 comments

image #Versions kotlin.version=1.9.0 agp.version=7.4.2 compose.version=1.4.3

settings.gradle.kts

plugins {
        val kotlinVersion = extra["kotlin.version"] as String
        val agpVersion = extra["agp.version"] as String
        val composeVersion = extra["compose.version"] as String

        kotlin("jvm").version(kotlinVersion)
        kotlin("multiplatform").version(kotlinVersion)
        kotlin("android").version(kotlinVersion)

        id("com.android.application").version(agpVersion)
        id("com.android.library").version(agpVersion)

        id("org.jetbrains.compose").version(composeVersion)
        //资源引用
        id("dev.icerock.mobile.multiplatform-resources").version("0.22.2")
    }

build.gradle.kts(:shared)

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("org.jetbrains.compose")
    //资源引用
    id("dev.icerock.mobile.multiplatform-resources")
}

kotlin {
    androidTarget()

    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        version = "1.0.0"
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../iosApp/Podfile")
        framework {
            baseName = "shared"
            isStatic = true
        }
        extraSpecAttributes["resources"] =
            "['src/commonMain/resources/**', 'src/iosMain/resources/**']"
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.runtime)
                implementation(compose.foundation)
                implementation(compose.material3)
                @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
                implementation(compose.components.resources)
                //三方图片控件
                implementation("media.kamel:kamel-image:0.7.1")
                //资源引用
                implementation("dev.icerock.moko:resources-compose:0.22.2")
            }
        }
        val androidMain by getting {
            dependencies {
                api("androidx.activity:activity-compose:1.6.1")
                api("androidx.appcompat:appcompat:1.6.1")
                api("androidx.core:core-ktx:1.9.0")
            }
        }
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
    }
}

android {
    compileSdk = (findProperty("android.compileSdk") as String).toInt()
    namespace = "com.myapplication.common"

    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    sourceSets["main"].res.srcDirs("src/androidMain/res")
    sourceSets["main"].resources.srcDirs("src/commonMain/resources")

    defaultConfig {
        minSdk = (findProperty("android.minSdk") as String).toInt()
        targetSdk = (findProperty("android.targetSdk") as String).toInt()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlin {
        jvmToolchain(11)
    }
}

Compilation of the generated MR file only occurs in commonMain and there are compilation errors, such as the screenshot shown above. Have you encountered this problem before? How can it be solved?

wangzhigang1112 avatar Sep 01 '23 06:09 wangzhigang1112

adding dependsOn(commonMain) in ios may fix the issue, I have fixed it in jvm

wakaztahir avatar Sep 03 '23 14:09 wakaztahir

The configuration you mentioned has been added to the ios section: dependsOn(commonMain), but it still failed. image In addition, we have reported the same issue in the Multiplatform Compose repository and many developers have also encountered this problem. However, it has not been resolved, and we still encounter the same problem. Multiplatform Compose ISSUE

wangzhigang1112 avatar Sep 04 '23 06:09 wangzhigang1112

It's like 531, You should also try to add depends on in all iOS modules that are failing

If that doesn't work, I got nothing

wakaztahir avatar Sep 04 '23 06:09 wakaztahir

i got exacly same problem with same plugins version it took me hole day but this worked 1.delete your build folder in shared module 2.make sure your build.gradle.kts (shared) is exacly configure like this:


plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("com.android.library") id("org.jetbrains.compose") id("com.squareup.sqldelight") id("dev.icerock.mobile.multiplatform-resources") }

kotlin { androidTarget()

listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "shared"
        export("dev.icerock.moko:resources:0.22.3")
        export("dev.icerock.moko:graphics:0.9.0")
    }
}

sourceSets {
    val commonMain by getting {
        dependencies { 
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
            implementation(compose.components.resources)

            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")

            implementation("io.ktor:ktor-client-core:2.3.2")
            implementation("io.ktor:ktor-client-content-negotiation:2.3.2")
            implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.2")

            implementation("com.squareup.sqldelight:runtime:1.5.5")

            api("dev.icerock.moko:mvvm-core:0.16.1") // only ViewModel, EventsDispatcher, Dispatchers.UI
            api("dev.icerock.moko:mvvm-compose:0.16.1") // api mvvm-core, getViewModel for Compose Multiplatfrom

            api("dev.icerock.moko:resources:0.22.3")
        }
    }
    val androidMain by getting {
        dependsOn(commonMain)
        dependencies {
            api("androidx.activity:activity-compose:1.7.2")
            api("androidx.appcompat:appcompat:1.6.1")
            api("androidx.core:core-ktx:1.10.1")

            implementation("io.ktor:ktor-client-android:2.3.2")
            implementation("com.squareup.sqldelight:android-driver:1.5.5")
        }
    }
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
        dependsOn(commonMain)
        iosX64Main.dependsOn(this)
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
        dependencies {
            implementation("io.ktor:ktor-client-darwin:2.3.2")
            implementation("com.squareup.sqldelight:native-driver:1.5.5")
        }
    }
}

}

android { compileSdk = (findProperty("android.compileSdk") as String).toInt() namespace = "com.attendace.leopard"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
    minSdk = (findProperty("android.minSdk") as String).toInt()
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
    jvmToolchain(11)
}

}

sqldelight { database("LeopardDb") { packageName = "com.attendace.leopard" } linkSqlite = true }

multiplatformResources { multiplatformResourcesPackage = "com.attendance.leopard" multiplatformResourcesClassName = "SharedRes" }


3.run your project and it would be work 4.if still got same error delete build folder again and "Rebuild" the project

the problem is that in generate files moko->androidMain&IosArm64Main and ... does not regonize they src folder as source root

adelsaramii avatar Sep 04 '23 12:09 adelsaramii

我在相同的插件版本上遇到了完全相同的问题, 这花了我一天的时间,但这有效 1.删除共享模块中的构建文件夹 2.确保你的build.gradle.kts(共享)完全配置如下:

插件 { kotlin("multiplatform") kotlin("plugin.serialization") id("com.android.library") id("org.jetbrains.compose") id("com.squareup.sqldelight") id("dev .icerock.mobile.multiplatform-resources") }

科特林 { androidTarget()

listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "shared"
        export("dev.icerock.moko:resources:0.22.3")
        export("dev.icerock.moko:graphics:0.9.0")
    }
}

sourceSets {
    val commonMain by getting {
        dependencies { 
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
            implementation(compose.components.resources)

            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")

            implementation("io.ktor:ktor-client-core:2.3.2")
            implementation("io.ktor:ktor-client-content-negotiation:2.3.2")
            implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.2")

            implementation("com.squareup.sqldelight:runtime:1.5.5")

            api("dev.icerock.moko:mvvm-core:0.16.1") // only ViewModel, EventsDispatcher, Dispatchers.UI
            api("dev.icerock.moko:mvvm-compose:0.16.1") // api mvvm-core, getViewModel for Compose Multiplatfrom

            api("dev.icerock.moko:resources:0.22.3")
        }
    }
    val androidMain by getting {
        dependsOn(commonMain)
        dependencies {
            api("androidx.activity:activity-compose:1.7.2")
            api("androidx.appcompat:appcompat:1.6.1")
            api("androidx.core:core-ktx:1.10.1")

            implementation("io.ktor:ktor-client-android:2.3.2")
            implementation("com.squareup.sqldelight:android-driver:1.5.5")
        }
    }
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
        dependsOn(commonMain)
        iosX64Main.dependsOn(this)
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
        dependencies {
            implementation("io.ktor:ktor-client-darwin:2.3.2")
            implementation("com.squareup.sqldelight:native-driver:1.5.5")
        }
    }
}

}

android { compileSdk = (findProperty("android.compileSdk") as String).toInt() 命名空间 = "com.attendace.leopard"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
    minSdk = (findProperty("android.minSdk") as String).toInt()
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
    jvmToolchain(11)
}

}

sqldelight { 数据库("LeopardDb") { packageName = "com.attendace.leopard" } linkSqlite = true }

multiplatformResources { multiplatformResourcesPackage = "com.attendance.leopard" multiplatformResourcesClassName = "SharedRes" }

3.运行您的项目,它将可以工作 4.如果仍然出现相同的错误,请再次删除构建文件夹并“重建”项目

问题是在生成文件 moko->androidMain&IosArm64Main 和 ... 中没有将它们 src 文件夹重新调整为源根目录

https://github.com/wangzhigang1112/MobileApp/blame/main/MobileApp.zip

i got exacly same problem with same plugins version it took me hole day but this worked 1.delete your build folder in shared module 2.make sure your build.gradle.kts (shared) is exacly configure like this:

plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("com.android.library") id("org.jetbrains.compose") id("com.squareup.sqldelight") id("dev.icerock.mobile.multiplatform-resources") }

kotlin { androidTarget()

listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "shared"
        export("dev.icerock.moko:resources:0.22.3")
        export("dev.icerock.moko:graphics:0.9.0")
    }
}

sourceSets {
    val commonMain by getting {
        dependencies { 
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
            implementation(compose.components.resources)

            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")

            implementation("io.ktor:ktor-client-core:2.3.2")
            implementation("io.ktor:ktor-client-content-negotiation:2.3.2")
            implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.2")

            implementation("com.squareup.sqldelight:runtime:1.5.5")

            api("dev.icerock.moko:mvvm-core:0.16.1") // only ViewModel, EventsDispatcher, Dispatchers.UI
            api("dev.icerock.moko:mvvm-compose:0.16.1") // api mvvm-core, getViewModel for Compose Multiplatfrom

            api("dev.icerock.moko:resources:0.22.3")
        }
    }
    val androidMain by getting {
        dependsOn(commonMain)
        dependencies {
            api("androidx.activity:activity-compose:1.7.2")
            api("androidx.appcompat:appcompat:1.6.1")
            api("androidx.core:core-ktx:1.10.1")

            implementation("io.ktor:ktor-client-android:2.3.2")
            implementation("com.squareup.sqldelight:android-driver:1.5.5")
        }
    }
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
        dependsOn(commonMain)
        iosX64Main.dependsOn(this)
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
        dependencies {
            implementation("io.ktor:ktor-client-darwin:2.3.2")
            implementation("com.squareup.sqldelight:native-driver:1.5.5")
        }
    }
}

}

android { compileSdk = (findProperty("android.compileSdk") as String).toInt() namespace = "com.attendace.leopard"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
    minSdk = (findProperty("android.minSdk") as String).toInt()
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
    jvmToolchain(11)
}

}

sqldelight { database("LeopardDb") { packageName = "com.attendace.leopard" } linkSqlite = true }

multiplatformResources { multiplatformResourcesPackage = "com.attendance.leopard" multiplatformResourcesClassName = "SharedRes" }

3.run your project and it would be work 4.if still got same error delete build folder again and "Rebuild" the project

the problem is that in generate files moko->androidMain&IosArm64Main and ... does not regonize they src folder as source root

Project File :https://github.com/wangzhigang1112/MobileApp/blame/main/MobileApp.zip I have checked your configuration and made the necessary modifications. However, the issue still exists. If you are interested, you can download the packaged project and take a look at the strange problem. Thank you.

wangzhigang1112 avatar Sep 05 '23 01:09 wangzhigang1112

This looks like moko resources issue after updating Kotlin version to 1.9.0 I also ran into same issue. It said has no actual declaration for JVM but, i didn't have JVM Target.

But adding dependsOn(common) in Android dependencies fixed it.

sdzshn3 avatar Sep 06 '23 19:09 sdzshn3

This looks like moko resources issue after updating Kotlin version to 1.9.0 I also ran into same issue. It said has no actual declaration for JVM but, i didn't have JVM Target.

But adding dependsOn(common) in Android dependencies fixed it.

"Android has a solution, but I haven't found one for iOS yet."

wangzhigang1112 avatar Sep 06 '23 23:09 wangzhigang1112

In here, after adding a dependsOn(commonMain) to androidMain, all the errors were gone and ios is working fine.

I have an ios source set that looks like this:

        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }

bcmedeiros avatar Sep 07 '23 17:09 bcmedeiros

In here, after adding a dependsOn(commonMain) to androidMain, all the errors were gone and ios is working fine.

I have an ios source set that looks like this:

        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }

"Still not working. What version of Kotlin are you using? My configuration is Kotlin 1.9.0."

wangzhigang1112 avatar Sep 08 '23 08:09 wangzhigang1112

I have faced with same problems on:

kotlin.version=1.9.0 agp.version=7.4.2 compose.version=1.5.0

Psihey avatar Nov 24 '23 15:11 Psihey

fix in #575

Alex009 avatar Jan 14 '24 14:01 Alex009

will be fixed in 0.24.0, please check in 0.24.0-alpha-6

ExNDY avatar Apr 17 '24 05:04 ExNDY

should be fixed in 0.24.0-beta-1

Alex009 avatar Apr 19 '24 15:04 Alex009