Has anyone had success with custom build configura...
# multiplatform
e
Has anyone had success with custom build configurations (those apart from debug and release) together with a MPP shared library? I have a configuration called PreProd that targets a different server url. When trying to build that configuration in iOS I get
No enum constant org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.PREPROD
. (Im using cocoapods)
k
I ran into something similar, but my names were SecureDebug and SecureRelease, so I was just able to remove 'Secure' on the command line call within the podspec
sounds like you might need to do something a little more advanced
e
Thanks. From what I understand the CocoaPods gradle plugin adds the debug and release frameworks and I guess iOS is trying to find a preProd one, or something like that. I’d be fine if it would just use release framework for preProd but I cannot figure out how.
k
it expects the configuration names to match in the iOS app and MPP. I think the easiest to figure out will be to add a new configuration to your MPP to match.
unfortunately I have not done that, but I would guess someone here has
e
That sounds reasonable but I cannot find any examples of adding configurations to the MPP.
i
I’d be fine if it would just use release framework for preProd but I cannot figure out how.
Currently adding a custom configuration (aka build type) to an MPP project is not supported. But you can edit a podspec generated by the CocoaPods plugin. The MPP build is started from a regular script phase (see
spec.script_phases
in the generated podspec). This script starts a Gradle build parametrized by the build configuration:
Copy code
$REPO_ROOT/gradlew ::syncFramework -Pkotlin.native.cocoapods.configuration=$CONFIGURATION
Since it's just a shell script, you can add a custom logic and set
kotlin.native.cocoapods.configuration
to
RELEASE
, if a
preProd
build is being executed.
e
Thank you for that. However, if I just hard-code the value
-Pkotlin.native.cocoapods.configuration="${CONFIGURATION/Release}"
when building my PreProd configuration I still get the same error (ive done pod install in between)
Oh wait the syntax was wrong. When testing with
-Pkotlin.native.cocoapods.configuration="Release"
it worked!
👍 1
k
mine looks like this:
-Pkotlin.native.cocoapods.configuration="${CONFIGURATION/Secure}"
which removes "Secure" from the config name
d
Just another show of hand that I ran into this issue too... Expected to be able to create a
Staging
configuration and failed - I'll use the podspec workaround too, but feels like this could be supported more gracefully.... production Apps often want to define extra configurations.
l
Is there any YouTrack issue for that?
m
Couldn’t find one
d
This is quite problematic when you're using the Cocoapods integration plugin, because the toolchain wants to continually overwrite
podspec
file, including the Gradle invocation to build the shared framework.
I used
noPodspec()
in the
cocoapods {...}
section to prevent the
podspec
file being overwritten - and to keep this change:
Copy code
spec.script_phases = [
        {
            :name => 'Build shared',
            :execution_position => :before_compile,
            :shell_path => '/bin/sh',
            :script => <<-SCRIPT
                set -ev
                [ $CONFIGURATION == "Staging" ] && KOTLIN_CONFIG="RELEASE" || KOTLIN_CONFIG="$CONFIGURATION"
                REPO_ROOT="$PODS_TARGET_SRCROOT"
                "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" :shared:syncFramework \
                    -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \
                    -Pkotlin.native.cocoapods.configuration=$KOTLIN_CONFIG \
                    -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \
                    -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \
                    -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"
            SCRIPT
        }
s
Is there any YouTrack issue for that?
https://youtrack.jetbrains.com/issue/KT-42023?
🙏 3