In our app we use the packForXCode task to copy th...
# multiplatform
j
In our app we use the packForXCode task to copy the framework to the correct folders. In this task we also copy some extra resources (assets.car) to the framework using doLast like in the following example:
doLast {
copy {
from("${project.rootDir}/android-app/src/commonMain/resources/ios")
into("${targetDir}/shared.framework")
}
}
What is the best approach to do this with the embedAndSignAppleFrameworkForXcode task? I was trying something like this (in the build script of the shared module):
tasks {
named("embedAndSignAppleFrameworkForXcode") {
doLast {
val targetDir = findProperty("configuration.build.dir")
// Copy resources here
}
}
}
But the message I get is: Task with name ‘embedAndSignAppleFrameworkForXcode’ not found in project ‘:shared’. I updated to Kotlin 1.5.30. The task is correctly ran from Xcode.
h
The task is only executable if you provide some environment variables, which are provided by Xcode by default. So you can't run them via terminal or IDEA, only with Xcode (except providing them manually)
j
Is there perhaps another hook to copy resources to the framework directory?
k
I think you should do it with ...linkFramework task which will be executed before embedding
l
@Jamie Craane I think you need harder gradle foo. Create a separate task that does the copying, and then make it depend on the embed task
j
The thing is with dependsOn, I cannot see the embed task at all when I output the gradle tasks using the “gradle tasks” command. The task is executed when using XCode but if I reference the “embedAndSignAppleFrameworkForXcode” in the gradle file I get an error the task does no exist. Going to try the link* tasks first.
Got it working with the the link* tasks by using doFirst. If anyone is interested the code for this is shown below (of course there are some hard paths in it now). The CONFIGURATION and SDK_NAME are set by XCode.
Copy code
named("linkDebugFrameworkIos") {
    doFirst {
        val configuration = System.getenv("CONFIGURATION")
        val sdkName = System.getenv("SDK_NAME")

        copy {
            from("${project.rootDir}/shared/src/commonMain/resources/ios")
            into("${project.buildDir}/xcode-frameworks/$configuration/$sdkName/shared.framework")
        }
    }
}
👍 1