we use Kotlin to share a library between Android and iOS.
We set up everything, but on iOS i need Bitcode enabled. After a research I found solution:
kotlin {
targets {
fromPreset(presets.jvm, 'jvm') {
mavenPublication {
artifactId = 'my-lib-name'
}
}
// Switch here to presets.iosArm64 to build library for iPhone device || iosX64 for emulator
fromPreset(presets.iosArm64, 'iOS') {
compilations.main.outputKinds('FRAMEWORK')
compilations.main.extraOpts '-Xembed-bitcode' // for release binaries
compilations.main.extraOpts '-Xembed-bitcode-marker'// for debug binaries
}
}
}
But the question is now, do I have and if yes, how do I separate between release and debug binaries and the specific flags? Can i simply add both flags without any drawbacks?
Maybe somebody can enlighten me thanks
Since Kotlin 1.3.20 bitcode embedding for iOS frameworks works out of the box. You also can configure embedding manually if you need:
kotlin {
iosArm64("ios") {
binaries {
framework {
// The following embedding modes are available:
// - "marker" - Embed placeholder LLVM IR data as a marker.
// Has the same effect as '-Xembed-bitcode-marker.'
// - "bitcode" - Embed LLVM IR bitcode as data.
// Has the same effect as the '-Xembed-bitcode'.
// - "disable" - Don't embed LLVM IR bitcode.
embedBitcode("marker")
}
}
}
}
Currently, all of the binary link tasks for the same iOS target share the compiler and linker options, so there's no way to setup the options for them separately. Please follow KT-26887 for updates.
If you can afford running several builds with different options, you can set the options conditionally and run the build with a flag:
compilations.main.outputKinds('FRAMEWORK')
if (project.findProperty("releaseFramework") == "true")
compilations.main.extraOpts '-Xembed-bitcode' // for release binaries
else
compilations.main.extraOpts '-Xembed-bitcode-marker'// for debug binaries
Then run the build with or without the flag, respectively:
./gradlew linkDebugFrameworkIOS
and
./gradlew linkReleaseFrameworkIOS -PreleaseFramework=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With