skip to Main Content

I am working on a KMM project and I need to create different Schema for my project eg (Dev, Production, QA) I can easily do it in android part but I am not able to create the same in iOS. I tried creating different schemas normally we do in iOS app but my app crashes with the error targeting to our packForXcode task in android studio.

Error while crash :- No enum constant org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEVELOPMENT Here I have created a custom schema named development

This error points to

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 targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}

Now into binaries I can see that there are two NativeBuildTargets DEBUG and RELEASE so I can run in both of these but how can I create a custom schema for my iOS app ?

2

Answers


  1. The problem is caused by the mode variable containing "configuration" value, which is not an appropriate build type from the Kotlin/Native compiler point of view(see some details in the documentation). To avoid it, one should redefine the function determining modes value. For example, it might be something like that:

    val mode = if (System.getenv("CONFIGURATION") != "release") "DEBUG" else System.getenv("CONFIGURATION")
    
    Login or Signup to reply.
  2. Below worked for me

    
    val packForXcode by tasks.creating(Sync::class) {
        group = "build"
        // Below line is important to solve it
        val mode = if (System.getenv("CONFIGURATION") != "release") "DEBUG" else System.getenv("CONFIGURATION")
        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 targetDir = File(buildDir, "xcode-frameworks")
        from({ framework.outputDirectory })
        into(targetDir)
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search