georgi
01/21/2022, 4:39 PMA
) declares a dependency on another KMM module (B
), the generated Swift code will prefix the classes from B
with its fully qualified module name when they are exposed through A
. For example, a class MyClass
defined in B
but exposed through A
will be available as BMyClass
when the A.framework
is used in Swift through embedAndSignAppleFrameworkForXcode
.
This is an issue when I have an interface which is defined in one module but implemented in another in which case Swift is not able to match the class names and does not consider the implementation as a valid argument when it is being passed as a parameter for example.
Any ideas about this? Thanks in advance!georgi
01/21/2022, 4:42 PMembedAndSignAppleFrameworkForXcode
in all Xcode modules that I'd like to use KMM code which isn't ideal. đgeorgi
01/21/2022, 5:33 PMTrevor Stone
01/21/2022, 5:37 PMexport()
Trevor Stone
01/21/2022, 5:38 PMexport(projectB)
kpgalligan
01/21/2022, 5:45 PMTrevor Stone
01/21/2022, 5:47 PMkpgalligan
01/21/2022, 5:48 PMTrevor Stone
01/21/2022, 5:49 PMTrevor Stone
01/21/2022, 5:49 PMval iOSBinaryConfig: KotlinNativeTarget.() -> Unit = {
binaries {
framework {
baseName = libraryName
for (moduleDependency in moduleDependencies) {
val apiProject = findProject("$moduleDependency:api")
apiProject?.let { export(it) }
}
xcf.add(this)
}
}
}
Trevor Stone
01/21/2022, 5:49 PMmoduleDependencies
is an internal variable in our scripts, so this isn't copy-pastable codekpgalligan
01/21/2022, 5:52 PMkpgalligan
01/21/2022, 5:53 PMapi
thing is interesting, though. Will put that into the mix of things weâre trying.Trevor Stone
01/21/2022, 5:53 PMTrevor Stone
01/21/2022, 5:54 PMkpgalligan
01/21/2022, 5:54 PMTrevor Stone
01/21/2022, 5:54 PMkpgalligan
01/21/2022, 5:56 PMTrevor Stone
01/21/2022, 5:57 PMTrevor Stone
01/21/2022, 6:09 PMapi
it did introduce some other complexities we had to work around in our build scripts (and if you misconfigure the binary validator it overwrites the folder named api) so another name might be helpful to use, and also be ready to work around some other things.kpgalligan
01/21/2022, 7:11 PMbe ready to work around some other thingsAlways đ
georgi
01/22/2022, 11:13 AMA
exposes a class Class
defined in module B
, then the class will be visible to swift as BClass
when linked using ./gradlew :A:embedAndSignAppleFrameworkForXcode
, unless I'm missing something...
I didn't know about the export(projectB)
option though so will read up on it and give it a try đgeorgi
01/22/2022, 8:30 PMexport(...)
trick worked by the way, thanks so much again!Sebastien Leclerc Lavallee
01/24/2022, 3:34 PMexport()
solved my issue! Thanks!Alen Kirm
01/31/2022, 8:29 AMexport()
does exactly what I need. Are there any potential limitations using this approach? Also noticed that transitiveExport
is not needed in this case?kpgalligan
01/31/2022, 7:50 PMexport()
can be a problem if you donât want to export the entire dependency. So, say you were using a library and just really needed 10% of it to be addressable in Swift, and maybe only use 50% of it total. 100% of the library is retained when exported (well, the public parts anyway). Anything you donât need winds up cluttering the header, but also each class that Swift needs to talk to gets some extra binary from the compiler to manage the objc interface. That can increase binary size, although âhow much?â is hard to say off hand. transitiveExport
has the same problems, but can be significantly worse if you have a lot of library code that either isnât used at all or doesnât need to be publicly visible to Swift.
Some discussion on binary size and visibility: Alen Kirm
02/01/2022, 11:55 AM