Currently, the name of a framework output comes from the folder structure of the gradle project. For example, a project located in myproject/common will be called common.framework.
I figured that this can be changed using:
fromPreset(iosPreset, 'ios') {
compilations.main.outputKinds('FRAMEWORK')
compilations.main.extraOpts '-output', 'newname'
}
However, the framework ends up in the project directory, not the build output directory.
How can I properly change the name of the generated framework?
Currently there is no such an option in the MPP plugin and the framework has the same name as the Gradle project. But such a feature is in short-term plans (see https://youtrack.jetbrains.com/issue/KT-26887).
In the meantime, is there a way to access the output binary path, so I could do something like so?
compilations.main.extraOpts '-output', "${outputPath}/newname.framework"
Using extraOpts may influence building a klib from main sources which is used to compile tests. So it's better to create a separate compilation for the framework. For compilations other than the main one the framework name matches the name of the compilation:
kotlin {
targets {
fromPreset(presets.macosX64, 'macos') {
compilations.create('myFramework') {
outputKinds = [ FRAMEWORK ]
}
}
}
sourceSets {
macosMyFramework.kotlin.srcDir 'src/macosMain/kotlin'
}
}
Thanks @ilmat192! That works well for now.
If it's helpful for others, I found I also had to add the common source set and dependency to the new source set:
sourceSets {
...
iosMyFramework {
kotlin.srcDirs += 'src/iosMain/kotlin'
kotlin.srcDirs += 'src/commonMain/kotlin'
dependencies {
implementation project(':common')
}
}
}
Most helpful comment
Thanks @ilmat192! That works well for now.
If it's helpful for others, I found I also had to add the common source set and dependency to the new source set: