I have a case where I need to adjust my build.grad...
# gradle
t
I have a case where I need to adjust my build.gradle.kts behavior based on context, from my Xcode project. That is, I am using the embedAndSignAppleFrameworkForXcode gradle task for my main app and my watchOS extension. But since I need to change how things are built for watchOS (it does not support CMP, so I need to skip that part). Any idea on how I can either detect the platform that is passed with that gradle task, or if I can pass a parameter from Xcode /CLI and then pick it up within the build.gradle? Thank you/
t
сс @Timofey Solonin
t
Hi.
embedAndSignAppleFrameworkForXcode
integration runs in an Xcode build phase and build settings from the project will be visible as environment variables in the build script. In particular you are probably interested in
PLATFORM_NAME
. In your build script you could write conditional logic based on those environment variables:
Copy code
// build.gradle.kts

if (providers.environmentVariable("PLATFORM_NAME").get() == "iphonesimulator") {
  // ... 
}
t
Excellent, I will give this a try. Thank you!
So that part worked, but trying to build watchOS target with Kotlin 2.0.10 not working out. It demands I include the compose compiler plugin, or it won't build. but if I include it, I get this:
Copy code
Showing Recent Messages
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: The Compose Compiler requires the Compose Runtime to be on the class path, but none could be found. The compose compiler plugin you are using (version 1.5.12) expects a minimum runtime version of 1.0.0.
Okay, I worked around it by commenting out the lines manually. For some reason, the if is not detected or used by some gradle process. If I don't do this, then it complains there is no plugin.
Copy code
if (!isBuildingCore) {
//                        implementation(compose.runtime)
//                        implementation(compose.foundation)
//                        implementation(compose.material3)
//                        implementation(compose.materialIconsExtended)
//                        implementation(compose.components.resources)
                    }
It would be great if the CMP team at least made stubs for watchOS. 🙂