https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
x

xxfast

12/22/2022, 1:57 AM
Hi all. I'm running into issues when exporting my sealed types across multiple modules. For example, my module setup is
Copy code
:app
⎿:feature-1
⎿:feature-2
:app
is the only module I'm depending on from iOS, but I am exporting my feature modules. I can export sealed types from
:app
just fine
Copy code
sealed class AppSealedType {
  object AppTypeA: AppSealedType()
  object AppTypeB: AppSealedType()
}
And they do show up on the swift side. However, when I define a seal type on one of the
:feature-x
modules
Copy code
sealed class FeatureSealedType {
  object FeatureTypeA: AppSealedType()
  object FeatureTypeB: AppSealedType()
}
Only the top seal interface is exported. I can trick the tooling to "force" export the sealed child types by referencing them in the
iosMain
of the
:app
as a workaround
Copy code
val FeatureTypeA = FeatureSealedType.FeatureTypeA
When I do that, the child types are exported Is this a known bug/limitation? Is there a way export all child types of my sealed types? More details in the 🧵
:app
is the only module I'm depending on from iOS, but I am exporting my feature modules
Copy code
iosMain {
 binaries {
  framework {
    baseName = "App"
    export(project(":feature-1"))
    export(project(":feature-2"))
  }
 }
}
I can export sealed types from
:app
just fine
Copy code
sealed class AppSealedType {
  object AppTypeA: AppSealedType()
  object AppTypeB: AppSealedType()
}
And they do show up on the swift side
Copy code
__attribute__((swift_name("AppSealedType")))
@interface AppSealedType : AppBase
@end

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("AppSealedType.AppTypeA")))
@interface AppSealedTypeAppTypeA : AppSealedType
..
@property (class, readonly, getter=shared) AppSealedTypeAppTypeA *shared __attribute__((swift_name("shared")));
@end
However, when I define a seal type on one of the
:feature-x
modules
Copy code
sealed class FeatureSealedType {
  object FeatureTypeA: AppSealedType()
  object FeatureTypeB: AppSealedType()
}
Only the top seal interface is exported
Copy code
__attribute__((swift_name("FeatureSealedType")))
@interface FeatureSealedType : PSCBase
@end
I can trick the tooling to "force" export the sealed child types by referencing them in the
iosMain
of the
:app
as a workaround
Copy code
val FeatureTypeA = FeatureSealedType.FeatureTypeA
When I do that, the child types are exported
Copy code
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("FeatureSealedType.FeatureTypeA")))
@interface FeatureSealedTypeFeatureTypeA : FeatureSealedType
@property (class, readonly, getter=shared) FeatureSealedTypeFeatureTypeA *shared __attribute__((swift_name("shared")));
@end
v

Vitor Hugo Schwaab

12/22/2022, 9:36 AM
Haven't faced this and can't dive deeper atm, but what if you use
api(project(":feature-1"))
instead of
implementation(project(":feature-1"))
and drop the
export
?
c

Corey

12/22/2022, 12:04 PM
@Vitor Hugo Schwaab I believe the
export
should be there, tho you're right if they change it from
implementation
to
api
it should work. Fixed a similar issue doing this.
a

ayodele

12/22/2022, 6:07 PM
It's intended. The compiler will shake down codes that ain't used outside the lib to reduce size, unless you explicitly reference them or you export it. But what we did was try to isolate each modules as possible, for example the
data
module depends on the
domain
but none of them was exported.
x

xxfast

12/22/2022, 11:13 PM
I've changed from
implementation
to
api
like
Copy code
sourceSets {
  val commonMain by getting {
    dependencies {
      api(project(":feature-1"))
      api(project(":feature-2"))
    }
  }
}
But I do still run into the same issue 🤔
Let me isolate the issue to a minimum reproducible project and open an issue on the issue tracker
9 Views