Kotlin-native: Bitcode support for iOS frameworks

Created on 29 Dec 2017  路  22Comments  路  Source: JetBrains/kotlin-native

Hi. Is there a way to generate an iOS framework that has bitcode enabled from the gradle plugin?
Currently ./gradlew build generates iOS frameworks for simulator and device but they don't seem to be bitcode enabled.

Most helpful comment

Bitcode is required to be enabled only in WatchOS

This part of statement is not correct. Both tvOS and watchOS require bitcode enabled now.

See https://developer.apple.com/tvos/submit/

When compiling your tvOS app and any third-party libraries, Bitcode must be enabled

So to summarize. Without bitcode you cannot develop any tvOS and watchOS frameworks/apps.
You can build an iOS application, but only as long as Apple does not make it required everywhere.
You can theoretically build an iOS framework with K/N, but you will have to make people disable bitcode in their apps, which is sometimes a blocker.

I completely understand that enabling bitcode is a complex feature, partially because Apple does whatever they want with LLVM. Same issue discussion in rust is open for 1,5 years already and with no ETA. However, IMO, K/N is in better position than Rust, because for Rust iOS support is a low-prio "good to have" feature, whereas K/N is devoted to client side from the beginning. My team is investigating now, whether we could ditch our 2 codebases on Java for Android/AndroidTV and Swift on iOS/tvOS to build one single K/N code and test base for all platforms. Everything looks too good to be true 馃槃 Except if there is no ETA for bitcode (even in 6 months from now), we won't be able to ship it to customers who use bitcode for a long time now and the whole idea falls apart. K/N FTW! 馃弾

(edit): I updated the comment to remove incorrect claim and clarify framework case, sorry about that.

All 22 comments

Not yet. Why do you need that functionality?

We have a large iOS project that uses bitcode. Xcode requires that if you enable bitcode, all your framework dependencies must also be built with bitcode.

On watchOS/tvOS that鈥檚 required. It is also likely in future this would be expanded to iOS.

Bitcode is required to be enabled only in WatchOS but if you have optionally enabled bitcode in your regular app, it is required that all frameworks that are included are also bitcode enabled.

Well, currently we cannot provide bitcode compatible with what Apple needs, so maybe just avoid using bitcode in the meantime.

Is it a technical limitation that would live past 1.0?

Bitcode is required to be enabled only in WatchOS

This part of statement is not correct. Both tvOS and watchOS require bitcode enabled now.

See https://developer.apple.com/tvos/submit/

When compiling your tvOS app and any third-party libraries, Bitcode must be enabled

So to summarize. Without bitcode you cannot develop any tvOS and watchOS frameworks/apps.
You can build an iOS application, but only as long as Apple does not make it required everywhere.
You can theoretically build an iOS framework with K/N, but you will have to make people disable bitcode in their apps, which is sometimes a blocker.

I completely understand that enabling bitcode is a complex feature, partially because Apple does whatever they want with LLVM. Same issue discussion in rust is open for 1,5 years already and with no ETA. However, IMO, K/N is in better position than Rust, because for Rust iOS support is a low-prio "good to have" feature, whereas K/N is devoted to client side from the beginning. My team is investigating now, whether we could ditch our 2 codebases on Java for Android/AndroidTV and Swift on iOS/tvOS to build one single K/N code and test base for all platforms. Everything looks too good to be true 馃槃 Except if there is no ETA for bitcode (even in 6 months from now), we won't be able to ship it to customers who use bitcode for a long time now and the whole idea falls apart. K/N FTW! 馃弾

(edit): I updated the comment to remove incorrect claim and clarify framework case, sorry about that.

I totally agree with @oleksandr-yefremov! We start a new SKD project that is 90% business logic, so we're starting it in Kotlin, with the expectations that it will advance quickly and it will support Bitcode and Dynamic Library in the next time (6 months is good enough). Will be a real blow if it doesn't, but we're willing to take the risk.

It appears that Rust has recently added support for outputting Bitcode: https://github.com/rust-lang/rust/pull/48896, in case that work provides any useful pointers for Kotlin Native.

Is there any news on this topic? We're also considering K/N but support for iOS bitcode is also a blocking point for us. Thanks

Created a ticket on YouTrack for this since it seems like things are more frequently responded to by Jetbrains over there: https://youtrack.jetbrains.com/issue/KT-27147

Not exactly bitcode, what we support is adding markers showing Apple tools that produced code is aware about bitcode and could be used with it. So please try and let us know about your results.

Have someone any experience with this compiler option "-Xembed-bitcode"? Does apple reject apps with this marker ?

We've just uploaded iOS app to iTunes Connect using -Xembed-bitcode without any problems. If your iOS project has ENABLE_BITCODE flag set, and any of the included frameworks does not provide bitcode, the archive operation will fail (and you cannot upload it to iTunes).

ps: iOS Framework that we are using was built from kotlin-native project with -xembed-bitcode marker.

@webfrea-k you uploaded to AppStore connect... Was the app approved and did you publish it in the App Store?

@gimlids no, we did not send it to approval. It was just for testing if technicality speaking app is compliant with AppStore. We were concerned if upload will fail due to some internal bitcode checking mechanism.

I'm confused - is bitcode working or not?

I did a quick and dirty test and it seemed to be working. I created a dummy Kotlin Native framework:

$(HOME)/lib/kotlin-native-macos-1.3.31/bin/kotlinc-native -produce framework -target ios_arm32  -Xembed-bitcode -o armv7/KLib lib.kt
$(HOME)/lib/kotlin-native-macos-1.3.31/bin/kotlinc-native -produce framework -target ios_arm64  -Xembed-bitcode -o arm64/KLib lib.kt
cp -R arm64/* universal
rm universal/KLib.framework/KLib
lipo armv7/KLib.framework/KLib arm64/KLib.framework/KLib -create -output universal/KLib.framework/KLib

Then I added the framework to a new app, archived it, and exported it with the "Rebuild from Bitcode" option using my enterprise cert. It seems to work fine.

Screenshot 2019-06-15 07 58 32

I've been searching for an alternative to C++ for sharing code between iOS and Android libraries, however lack of iOS bitcode support originally turned me away. If it is working, Kotlin/Native seems like an exciting option :)

I've uploaded an iOS app to the App Store with the Bitcode option selected - there was no error or warning. Yet after processing there is no "Download dSYM" link. Doesn't that indicate that the binaries haven't been rebuilt?

Not exactly bitcode, what we support is adding markers showing Apple tools that produced code is aware about bitcode and could be used with it. So please try and let us know about your results.

So my understanding is iOS and tvOS would be supported, watchOS would not.

Not exactly bitcode, what we support is adding markers showing Apple tools that produced code is aware about bitcode and could be used with it.

This will become false with 1.3.50, which is going to include real bitcode support.

So my understanding is iOS and tvOS would be supported, watchOS would not.

Please note that "bitcode support" is not exactly the same as "watchOS support". The latter would also require other efforts.

Fixed in 1.3.50.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benasher44 picture benasher44  路  4Comments

jonnyzzz picture jonnyzzz  路  4Comments

Marcopohlo picture Marcopohlo  路  4Comments

tarek360 picture tarek360  路  4Comments

msink picture msink  路  4Comments