Question on how best support older versions of Kot...
# android
n
Question on how best support older versions of Kotlin in the android variant of our Kotlin Multi Platform SDK when using Kotlin 1.9
c
Could you edit your question to put more of it in the thread? See: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1616265877303000
👍 1
n
Hey all, we have a multi module KMP SDK and we want to move to kotlin 1.9 but we want/need to compile and support for older versions of koltin (1.7+) for android. currently we have this in our main core
build.gradle.kts
, that we share across ios. js and android
Copy code
kts
sourceSets.all {
    languageSettings.apply {
        languageVersion = "1.7"
        apiVersion = "1.7"
    }
}
sourceSets {
    // commonMain
    // commonTest
    // etc
    val jsMain by getting {
            languageSettings.apply {
                languageVersion = "1.9"
                apiVersion = "1.9"
            }
        }
    
    val jsTest by getting {
            languageSettings.apply {
                languageVersion = "1.9"
                apiVersion = "1.9"
            }
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
}
and this in our
build.gradle.kts
for android
Copy code
kts
android {
    namespace = "some.namespace"
    compileSdk = 31
    defaultConfig {
        minSdk = 24
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles("<http://consumer-rules.pro|consumer-rules.pro>")
    }
    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "<http://proguard-rules.pro|proguard-rules.pro>"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlin {
        jvmToolchain(11)
    }
    kotlinOptions {
        jvmTarget = "11"
        languageVersion= "1.7"
        apiVersion = "1.7"
    }
}
but when we try to consume the sdk in an completely separate android sample app we get this error, (our internal test app builds fine as it uses the same 1.9 build chain)
Copy code
/user/someuser/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.0/kotlin-stdlib-common-1.9.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
but if we add this to the android app
build.gradle.kts
It builds and runs fine, but asking customers to add this to their app is not ideal, is there a way to fix this in the sdk? or is there a better way to do this?
Copy code
kts
allprojects {
    tasks.withType(KotlinCompile).configureEach {
        kotlinOptions {
            freeCompilerArgs += [
                    "-Xskip-metadata-version-check"
            ]
        }
    }
}
c
I'd try posting in #multiplatform