Hey friends, anyone have any solutions for classna...
# kotlin-native
a
Hey friends, anyone have any solutions for classname collisions across Gradle modules when building an iOS framework? My understanding is that I have to build a single framework file using
export
to bundle all the separate projects together. Throughout our Kotlin codebase we have packages like
com.quizlet.module1.models.StudySet
and
com.quizlet.module2.models.StudySet
where the implementations of the
StudySet
classes are a bit different depending on the module. This is currently causing issues for us because one of them gets mapped to
QuizletFramework.StudySet
and the other to
QuizletFramework.StudySet_
A few questions: 1. Am I correct that we have to build one mega-Framework instead of just having multiple frameworks with different names to avoid these collisions? 2. Is it potentially possible to have classes from each module prefixed with a unique value when exporting into one framework? 3. Is there any way around name collisions besides just ensuring that every class has a unique name? 4. Is there a way to enforce that there are no collisions at compile-time instead of running into the issue once we try consuming the framework later?
k
I’d like to chat about this. It’s come up a few times in our discussions with other teams. I’ve spent some time in the interop header gen space, so I think there are ways to make this better. Can’t talk now, but would like to get thoughts and propose something.
👍 1
a
DMed - definitely happy to chat about this. If there's any currently-existing way of dealing with this issue, I'm also interested in hearing folks out 🙂
k
I'm also looking into same issues, and created small example, related to most of your questions and possible solutions: https://github.com/Ekahau/khtf
Brief answers: 1. Yes, you will need to create one additional project, that will compile required libs into single FW. For jvm, it is possible to use libs directly. 2. Probably konan compiler could be modified. But if you ask that question, you may no want to go that route. 3. There is no collisions. Same names got '_' suffix. See example in the project that I shared (framework project) 4. There are no collisions at runtime, as kotlin compiler ensures that (my subjective understanding).
When I reread your question I realized that I may not understood it correctly 🙂
If the goal to pass around classes with suffixed names, maybe you have to change names Like StudySetModule1, StudySetModule2, etc
a
Ah yes “collision” is probably the wrong word. I understand that there are no runtime issues. The issue is that some of my teammates need to access those
StudySet
and
StudySet_
classes from ObjC/Swift. Dealing with the underscores is a very unpleasant experience for developers who have nothing to do with writing KMPP, and it is definitely hindering adoption at our company. It’s also very annoying to have to rename classes to be globally unique across all modules when many of the Kotlin modules are completely unaware of each other and its just the one big bridge project that knows about thema ll. In a production situation with multiple modules being worked on by multiple teams, how is Team A supposed to know that Team B has a class with the same name?
n
I wonder if it's technically possible to have more than one module in a single iOS/Mac framework, this way Gradle modules could be mapped to clang modules, giving types some breathing room.
k
There’s work currently happening in the KN repo to allow multiple frameworks, so anything in this realm will probably be best held till then. https://github.com/JetBrains/kotlin-native/pull/3457
n
yeah but having even a poor namespacing inside a single framework seems beneficial