touchlab-lab / KaMPKitSQLCipher

Apache License 2.0
6 stars 0 forks source link

Cannot create binary debugFramework: binary with such a name already exists #2

Open ln-12 opened 3 years ago

ln-12 commented 3 years ago

I am trying to integrate SQLDelight together with SQLCipher into my existing Kotlin Multiplatform Mobile project. I am now stuggling with the correct configuration. My shared build.gradle.ktslooks the following:

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    id("com.android.library")
    id("com.squareup.sqldelight")
    id("dev.icerock.mobile.multiplatform-resources")
    id("co.touchlab.native.cocoapods")

}

group = "com.jetbrains.handson"
version = "1.0-SNAPSHOT"

repositories {
    gradlePluginPortal()
    google()
    jcenter()
    mavenCentral()
    maven(url = "https://kotlin.bintray.com/kotlinx/")
    maven(url = "https://dl.bintray.com/icerockdev/moko")
    maven(url = "https://dl.bintray.com/korlibs/korlibs/")
}

kotlin {
    android()

    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }

    version = "1.0"

    cocoapodsext {
        summary = "Common library for the KaMP starter kit"
        homepage = "https://github.com/touchlab/KaMPKit"
        pod("SQLCipher", "~> 4.0")
        framework {
            isStatic = true
            transitiveExport = true
        }
    }

    val sqlDelightVersion: String by project

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2-native-mt")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.1")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")

                // SQLDelight
                implementation("com.squareup.sqldelight:runtime:$sqlDelightVersion")
                implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelightVersion")

                // Bluetooth
                //implementation("dev.bluefalcon:library:0.8.0")

                // Crypto (SHA256, PBKDF2)
                implementation("com.soywiz.korlibs.krypto:krypto:2.0.1")

                // Koin
                api("org.koin:koin-core:3.0.0-alpha-4")

                // Multiplatform resources
                api("dev.icerock.moko:resources:0.13.1")

                // Logging
                implementation("com.github.aakira:napier:1.4.0")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.squareup.sqldelight:android-driver:$sqlDelightVersion")
                implementation("com.squareup.okhttp3:okhttp:4.9.0")
                implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")

                implementation("net.zetetic:android-database-sqlcipher:4.4.2")
                implementation("androidx.sqlite:sqlite:2.1.0")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.1")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation("com.squareup.sqldelight:native-driver:$sqlDelightVersion")
                implementation("co.touchlab:sqliter:0.7.1")
            }
        }
        val iosTest by getting
    }
}

// moko resources
multiplatformResources {
    multiplatformResourcesPackage = "com.jetbrains.handson" // required
    iosBaseLocalizationRegion = "en" // optional, default "en"
    multiplatformResourcesSourceSet = "commonMain"  // optional, default "commonMain"
}

android {
    compileSdkVersion(30)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(21)
        targetSdkVersion(30)
        versionCode = 1
        versionName = "1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
}

sqldelight {
    database("AppDatabase") {
        packageName = "com.jetbrains.handson.kmm.shared.cache"
        linkSqlite = false
    }
}

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName  = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs = listOf(
            *freeCompilerArgs.toTypedArray(),
            "-Xallow-jvm-ir-dependencies",
            "-Xskip-prerelease-check",
            "-Xopt-in=kotlin.RequiresOptIn"
        )
    }
}

This config leads to the error Cannot create binary debugFramework: binary with such a name already exists. When I comment out binaries block inside ios {}, the error is Key debugFramework is missing in the map. What am I doing wrong? Could you provide me a correct config?

kpgalligan commented 3 years ago

You can't mix explicit framework config and cocoapods config.

    ios {
        binaries {
            framework { //You can't use this and cocoapodsext in the same config
                baseName = "shared"
            }
        }
    }

    version = "1.0"

    cocoapodsext {
        summary = "Common library for the KaMP starter kit"
        homepage = "https://github.com/touchlab/KaMPKit"
        pod("SQLCipher", "~> 4.0")
        framework {
            isStatic = true
            transitiveExport = true
        }
    }
ln-12 commented 3 years ago

And what would you suggest do? Which changes do I have to make to the default KMM temaple? As mentioned above, leaving out the explicit block leads to the error Key debugFramework is missing in the map. in the packForXcode section. If I comment out the section, the error becomes Task 'packForXCode' not found in project ':shared'..

ln-12 commented 3 years ago

For now I fixed it by copying the kampkit ios files into my project and then copied my UI files in the kampkit folder. So it seems like there has to be done some config in the XCode files, but I can't see which.