aidanvii
08/13/2024, 12:09 PM@HiddenFromObjC
, where you can expose public APIs for Kotlin, then disable ObjC export of public APIs (unless explicitly allowed) by default.
I’ve seen issues with Obj-C export with some cases where it just craps out, I think it may have been some public compose functions. We took the approach of literally marking EVERYTHING as internal
unless explicitly required. The alternative being obscene levels of modularisation and explicitly exporting modules with things you need on Swift/ObjC side.agrosner
08/13/2024, 1:12 PMagrosner
08/13/2024, 1:12 PMaidanvii
08/13/2024, 1:24 PM@HiddenFromObjC
. Basically, it would be a lot less cumbersome if it was possible to explicitly export a select few APIs. As it stands, my only option is to split into 2 modules and do the following:
1. module A with the public API that I want to export to ObjC
2. module B with the public API that I don’t want to export to ObjC, but available in consuming Kotlin modules (this would depend on the module A)
3. The consuming shared/composeApp module then has:
a. an api dependency for module A with ObjC export
b. an implementation dependency for module B without ObjC exportaidanvii
08/13/2024, 1:32 PMRick Clephas
08/13/2024, 2:46 PMThe problem is worsened by some public APIs causing compilation failuresPlease report those, if they haven’t already been reported.
where modularisation becomes the only option.True, but IMO most of the time this is fairly straightforward. Could you share some more details on your use case regarding wanting to share declarations with other Kotlin modules, but not with ObjC consumers? Why aren’t such declarations needed in ObjC, and why would you still like them to be in the shared Kotlin module? E.g. what is the issue with having another Kotlin module with the common Kotlin declarations (that isn’t used from ObjC)?
aidanvii
08/13/2024, 2:57 PM@Composable
declaration it wasn't happy about. In a typical compose multiplatform app, there is very little that needs to be be exported for Swift/ObjC, which is obviously not the case for a more traditional KMP app where you would need access to much more of the shared code from the Swift side.XinzhengZhang
04/27/2025, 2:40 PM-ObjC
because we used Categories, which resulted in the loss of the linker's ability to strip unused code in ObjC.
Although the explicit API mode
can solve this problem, due to the good strip (Code shrinking) capabilities of Kt-jvm and agp, a large number of our codes that have been ported from Kt-jvm to kt-Native (iOS) also do not have clear markings for visibility. Often, the interface layer of iOS only needs a very small number of interfaces, which binds a large amount of ObjC code, resulting in a huge waste of size. We have calculated that the same Kotlin symbol may be 7-8 times larger after one ObjC binding. So I also think it would be nice if there's a reverse operation for @HiddenFromObjC
.
By the way, I'm trying to implement a Kotlin Compiler Plugin to add @HiddenFromObjC
to Symbols by default. I tried adding annotations in the IrGenerationExtension
phase, but it didn't seem to work. I need some hints on which phase I should start with?...Rick Clephas
04/27/2025, 2:43 PM@HiddenFromObjC
annotation with a plugin. The ObjC export uses FIR output which doesn't provide a way to add the annotations.loke
04/28/2025, 4:55 AMinternal
.XinzhengZhang
05/07/2025, 10:50 AM