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
.
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?
Ok, so I finally figured it out (kind of).
Running embedAndSign
task in a CocoaPods project to set a gradle.properties
is wrong. As discussed in the original issue, it can lead to linking issues and generally does not make much sense, as the shared
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 the shared
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
:
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
-Pkotlin.native.cocoapods.archs="$ARCHS" \
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
After that you have to map the new iOS configurations to corresponding NativeBuildType
s:
xcodeConfigurationToNativeBuildType["iOSConfigName"] = NativeBuildType.DEBUG
The configuration name can then be accessed inside the shared
module using findProperty(KotlinCocoapodsPlugin.CONFIGURATION_PROPERTY)
and gradle.properties
can be set according to it using the setProperty
method.
For more details see github thread that talks specificaly about setting a flavor for the shared
module based on target.