Hey guys, I created a library in multiplatform in ...
# multiplatform
v
Hey guys, I created a library in multiplatform in intellij. In my
settings.gradle.kts
Copy code
pluginManagement {
    repositories {
        google()
        gradlePluginPortal()
        mavenCentral()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "com.android") {
                useModule("com.android.tools.build:gradle:4.1.2"). // what is the use of 4.1.2 in here?
            }
        }
    }
}
rootProject.name = "xyz"
I commented in my code. Can someone guide what is the use of 4.1.2 that piece of code?
m
That's your version of the Android Gradle Plugin
4.1.2 is relatively old, I'd recommend using 7+
v
I am getting error when I update to latest one
e
also that block is not necessary since 4.2.0 because the plugin marker artifacts are published to gmaven
☝️ 1
v
Copy code
resolutionStrategy {
    eachPlugin {
        if (requested.id.namespace == "com.android") {
            useModule("com.android.tools.build:gradle:7.2.0")
        }
    }
}
should I remove whole block?
@ephemient @mbonnin
e
you can write
useVersion("7.2.0")
if you don't want to use other ways to set the plugin version
but whatever build issues you're having with newer versions are probably a gradle or agp issue, not a kotlin issue
v
Copy code
Build file '/Users/vmodi/IdeaProjects/abc/build.gradle.kts' line: 1

Plugin [id: 'com.android.application'] was not found in any of the following sources:
gradle-wrapper.properties
Copy code
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
build.gradle.kts
Copy code
plugins {
    kotlin("multiplatform") version "1.6.21"
    id("com.android.application")
}

group = "com.abc"
version = "0.0.1"

repositories {
    google()
    mavenCentral()
}

kotlin {
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    sourceSets {
        val ktorVersion = "2.0.0"
        val commonMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-logging:$ktorVersion")
                implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
                implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
                implementation("io.ktor:ktor-client-auth:$ktorVersion")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.3.2")
                implementation("io.insert-koin:koin-core:3.2.0-beta-1")
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
                implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
            }
            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)
                dependencies {
                    implementation("io.ktor:ktor-client-darwin:$ktorVersion")
                }
            }
        }
    }
}

android {
    compileSdk = 21
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        applicationId = "com.abc.kotlinmultiplatform"
        minSdk = 21
        targetSdk = 31
    }
    @Suppress("UnstableApiUsage")
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}
@mbonnin @ephemient 👆
m
Why do you have iosX64Main .. iosMain declared inside androidMain?
v
Is auto generated, I didn't do anything