ttypic / swift-klib-plugin

Gradle Plugin for injecting Swift code into Kotlin Multiplatform Mobile shared module
MIT License
212 stars 11 forks source link

impossible sync with new wizard template #28

Closed elviss116 closed 1 month ago

elviss116 commented 6 months ago

Hi, I can't sync my project after add your plugin:

`

import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {

alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsCompose)
//alias(libs.plugins.klibPlugin)
id("io.github.ttypic.swiftklib") version "0.5.1"

}

kotlin { androidTarget { compilations.all { kotlinOptions { jvmTarget = "11" } } }

listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "ComposeApp"
        isStatic = true
    }
}

sourceSets {

    androidMain.dependencies {
        implementation(libs.compose.ui.tooling.preview)
        implementation(libs.androidx.activity.compose)
    }
    commonMain.dependencies {
        implementation(compose.runtime)
        implementation(compose.foundation)
        implementation(compose.material)
        implementation(compose.ui)
        implementation(compose.components.resources)
        implementation(compose.components.uiToolingPreview)
    }
}

}

android { namespace = "org.kmp.klib.plugin" compileSdk = libs.versions.android.compileSdk.get().toInt()

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
    applicationId = "org.kmp.klib.plugin"
    minSdk = libs.versions.android.minSdk.get().toInt()
    targetSdk = libs.versions.android.targetSdk.get().toInt()
    versionCode = 1
    versionName = "1.0"
}
packaging {
    resources {
        excludes += "/META-INF/{AL2.0,LGPL2.1}"
    }
}
buildTypes {
    getByName("release") {
        isMinifyEnabled = false
    }
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
    debugImplementation(libs.compose.ui.tooling)
}

}

`

error:

`

ttypic commented 6 months ago

Hey @elviss116,

Thanks for raising this! Could you please double-check whether the issues disappear after removing the swiftklib plugin? The errors you provided don't seem relevant to the plugin.

phatblat commented 5 months ago

I'm seeing the same issue in a project generated by the Kotlin Multiplatform Wizard. This is a project with "Shared UI" via Compose Multiplatform and Kotlin 2.0.

e: file:///Users/phatblat/dev/kmp/KMPWizard-swiftklib/composeApp/build.gradle.kts:14:5: Unresolved reference: androidTarget

Example repo: https://github.com/phatblat/KMPWizard-swiftklib

phatblat commented 5 months ago

I get the same errors in a project without the "Shared UI" and downgrading the template from Kotlin 2.0 to 1.9.23. See KMPWizard-swiftui

mohamad-abuzaid commented 4 months ago

I had same issue and I was able to fix it by using alias() in my build.gradle

Old gradle

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsCompose)
    alias(libs.plugins.composeCompiler)
    alias(libs.plugins.kotlinSerialization)
    alias(libs.plugins.ksp)
    id("io.github.ttypic.swiftklib") version "0.5.1"
}

Solution

toml version file:

[versions]
klib = "0.5.1"

[plugins]
klib = { id = "io.github.ttypic.swiftklib", version.ref = "klib" }

application gradle

plugins {
    alias(libs.plugins.kotlinMultiplatform) apply false
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.androidLibrary) apply false
    alias(libs.plugins.jetbrainsCompose) apply false
    alias(libs.plugins.composeCompiler) apply false
    alias(libs.plugins.kotlinSerialization)
    alias(libs.plugins.ksp) apply false
    alias(libs.plugins.klib) apply false
}

New gradle:

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsCompose)
    alias(libs.plugins.composeCompiler)
    alias(libs.plugins.kotlinSerialization)
    alias(libs.plugins.ksp)
    alias(libs.plugins.klib)
}

Hope this helps

IlyaGulya commented 3 months ago

@mohamad-abuzaid @phatblat Please test the 0.6.2 release of the plugin. This issue should be fixed now.

IlyaGulya commented 1 month ago

Closing this issue for now. Feel free to reopen if issue persists