https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
e

einar

09/26/2019, 1:06 PM
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

Kris Wong

09/26/2019, 1:26 PM
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

einar

09/26/2019, 1:50 PM
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

Kris Wong

09/26/2019, 1:53 PM
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

einar

09/26/2019, 3:00 PM
That sounds reasonable but I cannot find any examples of adding configurations to the MPP.
i

ilya.matveev

09/27/2019, 9:02 AM
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

einar

09/27/2019, 9:11 AM
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

Kris Wong

09/27/2019, 12:53 PM
mine looks like this:
-Pkotlin.native.cocoapods.configuration="${CONFIGURATION/Secure}"
which removes "Secure" from the config name
d

darkmoon_uk

01/04/2021, 10:47 AM
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

louiscad

01/04/2021, 1:44 PM
Is there any YouTrack issue for that?
m

Mayank

01/10/2021, 5:59 PM
Couldn’t find one
d

darkmoon_uk

01/11/2021, 7:31 AM
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

svyatoslav.scherbina

01/11/2021, 8:14 AM
Is there any YouTrack issue for that?
https://youtrack.jetbrains.com/issue/KT-42023?
🙏 3
26 Views