I upgraded to kotlin 1.5.30 and tried to use the n...
# multiplatform
c
I upgraded to kotlin 1.5.30 and tried to use the new cocoapods plugin features to get around this: https://youtrack.jetbrains.com/issue/KT-42023#focus=Comments-27-4880877.0-0 However now the xcode build just fails with this error:
Copy code
* What went wrong:
Task 'Debug' not found in root project 'KotlinCommon'.`
Why is it looking for a task called Debug???
l
Show us the XCode configurations you have
Kotlin only works with “DEBUG” and “RELEASE” configurations, so if you have other XCode configurations, the script will pass ``-Pkotlin.native.cocoapods.configuration=$CONFIGURATION` with an unsupported string
It is complaining about a
Debug
configuration, so maybe try changing it to
DEBUG
all caps
c
I have a lot of different Xcode configurations but isn't that what this new feature is supposed to handle?
xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = NativeBuildType.DEBUG
I have mapped all the configurations. Even "Debug" by itself, tho it is not one of my configs
v
Hi Carson, could you please share more details such as cocoapods block from build script and xcode configuration name you were building when got this error?
l
@Carson Holzheimer this new feature makes it so you don’t need to have a custom “packForXcode” task in your gradle file, and it helps with some syncing bugs. It still only handles two types of configurations from Xcode, RELEASE and DEBUG. So your Build Phase Run Script needs to map the configurations in Xcode to one of those two strings. If you are using cocoapods, the place to do this would be to specify
noPodspec()
in your shared mmp build.gradle, then edit the podspec file script to do the string manipulation there
c
@Luis so that Youtrack issue shouldn’t be marked as fixed? I’ll share my code…
xcode configs and cocoapods block:
Copy code
cocoapods {
        // Configure fields required by CocoaPods.
        summary = "Shared Kotlin code across iOS and Android"
        homepage = "redacted"
        ios.deploymentTarget = "12.0"
        podfile = project.file("../Podfile")
        framework {
            baseName = "KotlinCommon"
            isStatic = true
        }

        val apps = listOf("DMS", "WFM")
        val schemes = listOf("Prod", "Beta", "Labs", "QA")
        val listOfDebugConfigs = apps.flatMap { app ->
            schemes.map { scheme ->
                "$app Debug ($scheme)"
            }
        }
        val listOfReleaseConfigs = apps.flatMap { app ->
            schemes.map { scheme ->
                "$app Release ($scheme)"
            }
        }

        // Not sure why these are required but build fails without it
        xcodeConfigurationToNativeBuildType["WFM"] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
        xcodeConfigurationToNativeBuildType["DMS"] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
        xcodeConfigurationToNativeBuildType["Debug"] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG

        listOfDebugConfigs.forEach {
            xcodeConfigurationToNativeBuildType[it] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
        }

        listOfReleaseConfigs.forEach {
            xcodeConfigurationToNativeBuildType[it] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.RELEASE
        }
    }
l
Sorry @Carson Holzheimer, I actually misread your post. I checked the code changes on the issue you linked and it should work like you are saying
Could you provide more logs on the gradle task failing? Xcode should show more details. Why is it trying to find a task called “Debug”, right?
Ah maybe I got it
😮 1
You need to escape the spaces
c
haha I was actually going to try that but thought no that can’t be it
I’ll try
l
I don’t understand exactly what these bits do
Copy code
val listOfDebugConfigs = apps.flatMap { app ->
            schemes.map { scheme ->
                "$app Debug ($scheme)"
            }
        }
        val listOfReleaseConfigs = apps.flatMap { app ->
            schemes.map { scheme ->
                "$app Release ($scheme)"
            }
        }
Could you paste the generate podspec? Maybe we could figure out if the spaces are an issue by looking at it
👍 1
c
Copy code
Pod::Spec.new do |spec|
    spec.name                     = 'KotlinCommon'
    spec.version                  = '1.0'
    spec.homepage                 = 'redacted'
    spec.source                   = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }
    spec.authors                  = ''
    spec.license                  = ''
    spec.summary                  = 'Shared Kotlin code across iOS and Android'

    spec.vendored_frameworks      = "build/cocoapods/framework/KotlinCommon.framework"
    spec.libraries                = "c++"
    spec.module_name              = "#{spec.name}_umbrella"

    spec.ios.deployment_target = '12.0'

                

    spec.pod_target_xcconfig = {
        'KOTLIN_PROJECT_PATH' => ':',
        'PRODUCT_MODULE_NAME' => 'KotlinCommon',
    }

    spec.script_phases = [
        {
            :name => 'Build KotlinCommon',
            :execution_position => :before_compile,
            :shell_path => '/bin/sh',
            :script => <<-SCRIPT
                if [ "YES" = "$COCOAPODS_SKIP_KOTLIN_BUILD" ]; then
                  echo "Skipping Gradle build task invocation due to COCOAPODS_SKIP_KOTLIN_BUILD environment variable set to \"YES\""
                  exit 0
                fi
                set -ev
                REPO_ROOT="$PODS_TARGET_SRCROOT"
                "$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 \
                    -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \
                    -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \
                    -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"
            SCRIPT
        }
    ]
end
It does look like escaping spaces is the problem:
Copy code
/bin/sh -c /Users/carsonholzheimer/Library/Developer/Xcode/DerivedData/RedEye-bnxkyzimuyxvsiczcehnvfezhktc/Build/Intermediates.noindex/Pods.build/WFM\\\ Debug\\\ \\\(QA\\\)-iphonesimulator/KotlinCommon.build/Script-B9E7066122875376ACF9D124F6326B2D.sh

                REPO_ROOT="$PODS_TARGET_SRCROOT"
                "$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                     -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS"                     -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS"                     -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"

> Configure project :
Kotlin Multiplatform Projects are an Alpha feature. See: <https://kotlinlang.org/docs/reference/evolution/components-stability.html>. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.

Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'
Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'
Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'
Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'

FAILURE: Build failed with an exception.

* What went wrong:
Task 'Debug' not found in root project 'KotlinCommon'.
It’s seeing Debug as a gradle task for some reason. How would I fix that (preferably not changing xcode configs..
I assume that script is generated by the cocoapods plugin, is it time for a new Youtrack issue?
The previous logs that build succesfully:
Copy code
/bin/sh -c /Users/carsonholzheimer/Library/Developer/Xcode/DerivedData/RedEye-ediatwizneiykycbhcshsflepmrj/Build/Intermediates.noindex/Pods.build/WFM\\\ Debug\\\ \\\(QA\\\)-iphonesimulator/KotlinCommon.build/Script-76194415D0376B6F6C5FC66A6A58DEE6.sh


                APP_BUILD="$CONFIGURATION"
                if [[ APP_BUILD == *"Debug"* ]]
                then
                    APP_BUILD="DEBUG"
                else
                    APP_BUILD="RELEASE"
                fi
                REPO_ROOT="$PODS_TARGET_SRCROOT"
                "$REPO_ROOT/gradlew" -p "$REPO_ROOT" ::syncFramework                     -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET                     -Pkotlin.native.cocoapods.configuration=$APP_BUILD                     -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS"                     -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS"                     -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"

> Configure project :
Kotlin Multiplatform Projects are an Alpha feature. See: <https://kotlinlang.org/docs/reference/evolution/components-stability.html>. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.

Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'
Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'
Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'
Unable to detect Kotlin framework build type for CONFIGURATION=WFM Debug (QA) automatically. Specify 'KOTLIN_FRAMEWORK_BUILD_TYPE' to 'debug' or 'release'

The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
See <https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets>

> Task :compileKotlinIosX64
> Task :linkReleaseFrameworkIosX64
> Task :syncFramework

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See <https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings>

BUILD SUCCESSFUL in 29s
l
Sorry @Carson Holzheimer I think in your case when you have
"$app Debug ($scheme)"
in your build.gradle, you should try to do something like
"$app\\ Debug\\ ($scheme)"
or maybe
"\"$app Debug ($scheme)\""
Either that or in your podspec add quotes to your
$CONFIGURATION
variable in the script
c
I’ve tried 1,2,3 and 4 slashes 🤣 But I will try your last suggestion.
l
basically, when the script is running, it replaces
$CONFIGURATION
with
WFM Debug (QA)
but because it has spaces it breaks the script
❤️ 1
gradle stops reading by
WFM
and then it tries to run the “task”
Debug
because of the spaces
👍 1
Either you do that, or you change your configurations in Xcode to not have spaces, maybe underscores 😛
👍 1
c
Gotta try not upset the iOS devs, you know 😄
😅 1
l
let me know if you get it working!
c
I didn’t manage to get it working. I’ll leave the
noPodspec
workaround in for the moment and make a Youtrack issue
👍 1