Skip to content

Whats the right way to use swiftklib?  #54

@Kashif-E

Description

@Kashif-E

this is how i am trying to do it

import io.github.ttypic.swiftklib.gradle.api.ExperimentalSwiftklibApi

plugins {
    alias(libs.plugins.multiplatform)
    alias(libs.plugins.android.library)
    alias(libs.plugins.kotlinx.serialization)
    id("convention.publication")
    alias(libs.plugins.compose.compiler)
    alias(libs.plugins.compose)
    alias(libs.plugins.swiftKlib)
}

group = "com.mia.stripe"
version = "1.0.0"

kotlin {

    jvmToolchain(17)

    androidTarget { publishLibraryVariants("release") }
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.compilations {
            val main by getting {
                cinterops {
                    create("MiaStripe")
                }
            }

        }
    }
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(libs.kotlinx.coroutines.core)
                implementation(compose.foundation)
                implementation(compose.runtime)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(libs.kotlinx.coroutines.android)
                implementation("com.stripe:stripe-android:20.41.0")
                implementation("com.stripe:stripe-java:25.3.0")
                implementation(libs.androidx.activityCompose)
            }
        }
        val androidUnitTest by getting
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }


    //https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers
    targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
        compilations["main"].compileTaskProvider.configure {
            compilerOptions {
                freeCompilerArgs.add("-Xexport-kdoc")
            }
        }
    }

}

android {
    namespace = "com.mia.stripe"
    compileSdk = 35

    defaultConfig {
        minSdk = 21
    }
}


swiftklib {
    create("MiaStripe") {
        path = file("src/iosMain/swift/mia")
        packageName("com.mia.stripe.ios")
        minIos = "14.0"
        @OptIn(ExperimentalSwiftklibApi::class)
        dependencies {
            remote(listOf("StripeCore", "StripePaymentSheet")) {
                url("https://github.com/stripe/stripe-ios.git", "stripe-ios")
                exactVersion("24.3.0")
            }
        }

    }

}
//kotlin.targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
//    compilations["main"].cinterops {
//        create("StripeIoxs") {
//            // defFile(project.file("src/nativeInterop/cinterop/stripeIos.def"))
//            packageName("com.stripe.ios")
//            compilerOpts("-framework", "Stripe")
//            // includeDirs.allHeaders("path/to/stripe/headers")  // If needed
//        }
//    }
//}

Task :stripeSdk:swiftklibMiaStripeIosSimulatorArm64
Fetching https://github.com/stripe/stripe-ios.git from cache
Fetched https://github.com/stripe/stripe-ios.git from cache (1.55s)
Computing version for https://github.com/stripe/stripe-ios.git
Computed https://github.com/stripe/stripe-ios.git at 24.3.0 (0.02s)
Creating working copy for https://github.com/stripe/stripe-ios.git
Working copy of https://github.com/stripe/stripe-ios.git resolved at 24.3.0
warning: 'swiftbuild': dependency 'stripe-ios' is not used by any target
'swiftbuild': dependency 'stripe-ios' is not used by any target

inside file mia
i have this code

import StoreKit
import UIKit
import StripeCore

and here StripeCore is undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions