Made a podspec today that can run gradle to genera...
# kotlin-native
b
Made a podspec today that can run gradle to generate the ios framework and properly integrates it into our project
👍 7
presumes a gradle task that can build a fat .framework
j
Is there an example for fat binary creation?
b
I'll post a gist of the tasks I made to do that (adapted from an SO post) tomorrow
j
Thanks!
b
I used
afterEvaluate
so that I could have typed access to those generated link tasks. If there's a better way, please comment! This is my first major custom gradle task
a
holy shit this is amazing
this would make an amazing gradle plugin
apply plugin "kotlin-cocoapods"
create this task and generate the podspec for you
if no one else does it i will 😛
b
definitely! please do. with my current gradle knowledge, i would spend a lot of time in just gradle plugin setup and understanding the plugin system in general, which i don't think is time i have right now. happy to contribute to the implementation parts of it though (i.e. implementation of task generation)
another thing to consider for the plugin is that you're left a bit on your own to figure out how to make gradle build for ios sim and device (if you're just looking at mpp examples I mean). we ended up doing this:
Copy code
kotlin {
    targets {
        // create targets for iOS sim and device
        fromPreset(presets.iosX64, 'iosSim') {
            compilations.main.outputKinds('FRAMEWORK')
        }
        fromPreset(presets.iosArm64, 'iosDevice') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    sourceSets {
        iosSimMain {
            kotlin.srcDirs += 'src/iosMain'
        }
        iosSimTest {
            kotlin.srcDirs += 'src/iosTest'
        }
        iosDeviceMain {
            kotlin.srcDirs += 'src/iosMain'
        }
        iosDeviceTest {
            kotlin.srcDirs += 'src/iosTest'
        }
    }
}
Would be nice if the mpp plugin let you specify multiple archs for platforms where building for multiple archs is common (i.e. ios, android native)
👍 1
tbh, we (somebody who knows how) should probably just update the kotlin-mpp plugin with those tasks I put in ios.gradle, and then the cp plugin would just generate a cocoapods podspec
j
Great, thanks for sharing. That's very helpful!
👍 1
a
oh i think you accomplish the same thing with your spec.user_target_xcconfig??? very nice
hmm the user_target_xcconfig stuff didnt work for mine it looks like. getting cannot find module compilation error and the
pbxproj
doesnt reflect the
user_target_xcconfig
(though maybe thats not whats supposed to happen)
b
Right this podspec doesn't check in the .framework either. The only issue with prepare_command is that it only runs at certain times, whereas the new script phase podspec dsl means you can make a build phase dependent on build files (suitable for updating and rebuilding kotlin)
Mine still might need some tweaking to be more universal; i've only tested it in our project. The idea behind
user_target_xcconfig
is that we have to setup the framework/linker flags ourselves because the podspec is building the framework (i.e. can't lean on
spec.vendored_frameworks
, which would generate the flags for us)
I might be able to help more, if I can see your podspec
a
is there somewhere in the IDE I can check the framework/linker flags to verify it was set up properly?
b
In Xcode? Yep. It depends how you did it, but you can go into the target you're integrating the framework into and look at build settings: 1. Find the project where that target lives 2. Select that project from the file list on the left 3. In the top left corner of the right window, select the target drop down (might currently show the proj file icon with your project showing, that means you're looking at project-wide build settings) 4. Select the target you're integrating your framework into 5. Select the "Build Settings" tab 6. Filter build settings for works like "linker" and "framework" (find linker options and framework search paths)
Also Dimitris K works at Square still right? He actively works on CocoaPods and is a good/nice person to talk to, if you all are in the same office 🙂
☝️ 1
Happy to continue helping here! Just wanted to make sure you were aware 🙂