Closed nealsanche closed 3 years ago
Okay, so, I worked on getting dependencies set up exactly as per the examples, and now, the error message, which at first thought was just the same as before, has actually changed to:
java.lang.IllegalArgumentException: Cannot change attributes of dependency configuration
So I guess I now have to figure out which attributes are different so the plugin doesn't have to try to change them after. Any clues?
can you show your build.gradle?
import com.greenwood.bank.Libs
import com.greenwood.bank.Versions
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("org.jetbrains.kotlin.plugin.serialization")
id("com.android.library")
id("com.apollographql.apollo").version("2.5.3")
id("dev.icerock.mobile.multiplatform-network-generator")
}
android {
compileSdkVersion(Versions.compileSdkVersion)
defaultConfig {
minSdkVersion(Versions.minSdkVersion)
targetSdkVersion(Versions.targetSdkVersion)
}
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
configurations {
create("androidTestApi")
create("androidTestDebugApi")
create("androidTestReleaseApi")
create("testApi")
create("testDebugApi")
create("testReleaseApi")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
apollo {
generateKotlinModels.set(true)
}
mokoNetwork {
spec("authspec") {
//isOpen = false
packageName = "com.greenwood.bank.services.auth"
}
}
kotlin {
android()
ios {
binaries {
framework {
baseName = "shared"
}
}
}
}
dependencies {
commonMainImplementation(Libs.Shared.Coroutines.common)
commonMainImplementation(Libs.Shared.DI.koin)
commonMainApi(Libs.Shared.Apollo.runtime)
commonMainApi(Libs.Shared.Ktor.client)
commonMainApi(Libs.Shared.Ktor.clientLogging)
commonMainApi(Libs.Shared.Kotlin.serialization)
commonMainApi("dev.icerock.moko:network:0.9.3")
commonMainApi("dev.icerock.moko:network-errors:0.9.3")
commonTestImplementation(Libs.Shared.KotlinTest.common)
commonTestImplementation(Libs.Shared.KotlinTest.annotations)
androidTestImplementation(Libs.Shared.KotlinTest.jvm)
androidTestImplementation(Libs.Shared.KotlinTest.junit)
androidTestImplementation(Libs.Shared.AndroidXTest.core)
androidTestImplementation(Libs.Shared.AndroidXTest.junit)
androidTestImplementation(Libs.Shared.AndroidXTest.runner)
androidTestImplementation(Libs.Shared.AndroidXTest.rules)
androidTestImplementation(Libs.Shared.Coroutines.test)
}
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)
Everything compiles and runs until I add the mokoNetwork DSL to the gradle file.
I just tried the -deprecated
generator and that works for my project. But, I suspect, as soon as I have more than a single spec, the new generator will need to be used, and it fails. I'll try and put together a minimal reproduction case, and put a link here.
Was not able to replicate this in a minimal app, so I started to look into why that might be and found that the errors are a result of a conflict of some sort with the Apollo GraphQL library. When Moko-Network and Apollo are both enabled, the gradle sync will always fail. I'll explore whether there is some sort of way around this.
Okay, knowing that there's an Apollo GraphQL incompatibility, I added the two conflicting plugins and the gradle sync fails in the same way due to the addition of this line:
https://github.com/nealsanche/MokoNetworkTest/blob/main/shared/build.gradle.kts#L8
I'm not sure how to get around this. Can Kotlin Multiplatform projects have multiple modules? Can one depend on the other? I guess that might be a way around this?
Yes you can use multiple modules. See moko-template as example
Apollo GraphQL put in a fix for this, so closing.
Adding this to a recent project I've been working on, and encountering the following errors when the Gradle import is occurring:
The top part of the stack trace that gets output is:
I suspect I'm probably just not using it right. This is a kotlin gradle script, and I know there can sometimes be differences in how Gradle and Kotlin DSL are implemented. Any ideas?