splendo / kaluga-swiftui

5 stars 0 forks source link

Will generated code work or not depends on the project structure #6

Open dasdranagon opened 3 years ago

dasdranagon commented 3 years ago

Currently, in documentation, nothing in the documentation said what the project structure should be to make generated code work. I have found few cases when it doesn't work.

It works if kaluga:resourses imported in a shared project and was not exported to a framework.

It doesn't work if

A concrete example.

We have a project with structure:

Root project 'SplendoHealth'
+--- Project ':fit'
+--- Project ':shared'
...
./gradlew :fit:dependencies | grep -E 'shared|resources'
...
+--- project :shared
|    +--- com.splendo.kaluga:resources:0.2.1
|    |    \--- com.splendo.kaluga:resources-iosarm64:0.2.1
....

In build.gradle.kts(:shared):

kotlin {
...
 sourceSets {
        commonMain {
            dependencies {
                  api("com.splendo.kaluga:resources:$kalugaVersion")
            }
        }
        .....
}

In build.gradle.kts(:fit):

kotlin {
      commonMain {
            dependencies {
                api(project(":shared"))
            }
     }
}

This structure will work with kaluga-swiftui

Now let's assume we have some code in shared we want to export in the framework. So we add such configuration in build.grade(:fit):

    val target: KotlinNativeTarget.() -> Unit =
        {
            binaries {
                framework {
                    isStatic = false
                    transitiveExport = true
                    export(project(":shared"))

                    linkerOpts("-F${rootProject.projectDir}/ios/Carthage/Build/iOS/")
                    linkerOpts("-ObjC")
                }
            }
        }

This structure will NOT work with kaluga-swiftui

The project will not compile because it will not find ResourcesColor

Daeda88 commented 3 years ago

We'll have to make resources a configuration flag. I want to do this for button styles anyway. Should be an easy fix