Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin Multiplatform library for iOS with bitcode

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

like image 634
Vario Avatar asked Nov 28 '18 20:11

Vario


2 Answers

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")
            }
        }
    }
}
like image 93
Ilya Matveev Avatar answered Nov 02 '22 09:11

Ilya Matveev


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
like image 26
hotkey Avatar answered Nov 02 '22 08:11

hotkey