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

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

Closed
wangzhigang1112 opened this issue Sep 1, 2023 · 13 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@wangzhigang1112
Copy link

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?

@wakaztahir
Copy link
Contributor

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

@wangzhigang1112
Copy link
Author

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

@wakaztahir
Copy link
Contributor

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

@adelsaramii
Copy link

adelsaramii commented Sep 4, 2023

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

@wangzhigang1112
Copy link
Author

我在相同的插件版本上遇到了完全相同的问题, 这花了我一天的时间,但这有效 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.

@sdzshn3
Copy link

sdzshn3 commented Sep 6, 2023

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.

@wangzhigang1112
Copy link
Author

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."

@bcmedeiros
Copy link

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)
        }

@wangzhigang1112
Copy link
Author

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."

@Psihey
Copy link

Psihey commented Nov 24, 2023

I have faced with same problems on:

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

@Alex009
Copy link
Member

Alex009 commented Jan 14, 2024

fix in #575

@Alex009 Alex009 added this to the 0.24.0 milestone Jan 14, 2024
@ExNDY
Copy link
Contributor

ExNDY commented Apr 17, 2024

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

@Alex009 Alex009 added the bug Something isn't working label Apr 19, 2024
@Alex009
Copy link
Member

Alex009 commented Apr 19, 2024

should be fixed in 0.24.0-beta-1

@Alex009 Alex009 closed this as completed Apr 19, 2024
@Alex009 Alex009 mentioned this issue Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants