Arkadii Ivanov
06/26/2020, 5:59 PMpackForXcode
Gradle task described here. But I'm getting the following error:
Unresolved reference: targets
. Basically kotlin.targets
is unresolved here 😞 Do you have any ideas how to solve it?Andrea Prearo
06/26/2020, 6:15 PMFatFrameworkTask
. There’s an example in the official documentation.John O'Reilly
06/26/2020, 6:18 PMArkadii Ivanov
06/26/2020, 6:21 PMJohn O'Reilly
06/26/2020, 6:22 PMAndrea Prearo
06/26/2020, 6:26 PMmacosX64
to the FatFrameworkTask
configuration”
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
kotlin {
// Create and configure the targets.
val ios32 = iosArm32("ios32")
val ios64 = iosArm64("ios64")
val macOS = macosX64()
configure(listOf(ios32, ios64, macOS)) {
binaries.framework {
baseName = "my_framework"
}
}
// Create a task building a fat framework.
tasks.create("debugFatFramework", FatFrameworkTask::class) {
// The fat framework must have the same base name as the initial frameworks.
baseName = "my_framework"
// The default destination directory is '<build directory>/fat-framework'.
destinationDir = buildDir.resolve("fat-framework/debug")
// Specify the frameworks to be merged.
from(
ios32.binaries.getFramework("DEBUG"),
ios64.binaries.getFramework("DEBUG")
macOS.binaries.getFramework("DEBUG")
)
}
}
Arkadii Ivanov
06/26/2020, 6:27 PMpackForXcode
a while ago and it worked. But now in an another project it does not.Andrea Prearo
06/26/2020, 6:30 PMmacOS
, you can just specify that.Arkadii Ivanov
06/26/2020, 6:31 PMpackForXcode
. As far as I understand fat frameworks are much more expensive to build, all architectures multiply debug/release. But normally you need just one, e.g. iosX64/debug. So packForXcode
does exactly this. It reads current config from Xcode env variables and builds what is required.Andrea Prearo
06/26/2020, 6:36 PM*.gradle.kts
file, kotlin.targets
should be available. It’s hard to tell where’s the problem without the full script code.russhwolf
06/26/2020, 6:39 PMkotlin.targets
isn't resolving it sounds like the multiplatform plugin isn't being applied correctly, but not sure why that would be.Arkadii Ivanov
06/26/2020, 6:43 PMval packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
kotlin {
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = targets
.getByName<KotlinNativeTarget>("macosX64")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
}
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText("#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$@\n")
gradlew.setExecutable(true)
}
}
I have replaced the kotlin.targets
thing with kotlin DSL kotlin {}
Andrea Prearo
06/26/2020, 6:43 PMplugins {
kotlin("multiplatform")
}
?Arkadii Ivanov
06/26/2020, 6:43 PMrusshwolf
06/26/2020, 6:44 PMkotlin { targets }
would resolve but kotlin.targets
would notArkadii Ivanov
06/26/2020, 6:47 PMlateinit var kotlin: KotlinMultiplatformExtension
kotlin { kotlin = this }
After that I can use kotlin.whatever
kotlin {}
russhwolf
06/26/2020, 6:48 PMArkadii Ivanov
06/26/2020, 7:08 PM