I used to use the following script build phase to set buildkonfig.flavor
property on kotlin version 1.19.20
and it worked fine:
cd "$SRCROOT/.." && ./gradlew :shared:embedAndSignAppleFrameworkForXcode -P buildkonfig.flavor=prod
But since updating to kotlin to version 2.0.0
, it does not compile and says:
'embedAndSign' task can not be used in a project with dependencies to pods.
I tried switching to any other task like build
, assemble
or generateBuildKonfig
, and moving the build phase up and down the list. It compiles & runs, but the property is not set.
Upon reverting back to original versions it turns out that the flavor is also not set when using other tasks instead of embedAndSignAppleFrameworkForXcode
.
So I guess the question is:
What other task can I use to set gradle property from XCode target’s build phases instead, since the embedAndSignAppleFrameworkForXcode
is now prohibited for CocoaPods?
2
Answers
Ok, so I finally figured it out (kind of).
Running
embedAndSign
task in a CocoaPods project to set agradle.properties
is wrong. As discussed in the original issue, it can lead to linking issues and generally does not make much sense, as theshared
module is already build as a pod.The
gradle.properties
cannot be set directly from the XCode project with CocoaPods. Information about the target/flavor should be instead passed into theshared
module using iOS configurations.First edit your iOS configurations so the name contains the target name. It can be done in project settings under the Info tab and CocoaPods should then automatically create corresponding configuration files under the
Pods
folder. Then edit each target scheme so the corresponding configuration is used.The configuration name is then automatically passed to the gradle when building the module inside the
shared.podspec
:The configuration name can then be accessed inside the
shared
module usingfindProperty(KotlinCocoapodsPlugin.CONFIGURATION_PROPERTY)
andgradle.properties
can be set according to it using thesetProperty
method.For more details see github thread that talks specificaly about setting a flavor for the
shared
module based on target.Unfortunately with the release of Kotlin 2.0.0-Beta5 the embedAndSign task isn’t possible anymore, since Jetbrains deactivated it.
YouTrack issue:
https://youtrack.jetbrains.com/issue/KT-64096/Diagnostic-when-embedAndSign-used-for-framework-with-cocoapods-dependencies#focus=Comments-27-9849651.0-0
GitHub commit:
https://github.com/jetbrains/kotlin/commit/7ab691fcef9eb91eae4771efc17ffd3170c297db