I have an Android project with several modules, the phone app module and some library modules. They all work with CoposeCompiler 1.2.0 and Kotlin version 1.7.0. Now, I'd like to add a WearOS module to create an app for smartwatches using JetpackCompose as well. The problem is that the latest stable version of ComposeCompiler for WearOS (1.1.1) does need Kotlin 1.6.10 to work, and won't build without that version.
I've tried to add Kotlin 1.6.10 as a dependency along with the existing one (1.7.0), but it thows an error when I try to build the project (duplicate classes). I did it in project-level Gradle file and module-level Gradle file.
I also tried to use the suppressKotlinVersionCompatibilityCheck=true
tag inside kotlinOptions
for WearOS module, but it also thows an error:
java.lang.NoSuchMethodError: 'boolean org.jetbrains.kotlin.ir.declarations.IrClass.isInline()'
I don't know how could I achive that. The only option that I seem fasible is to create another project specifically for the WearOS app, but I'd like to have all the modules together in a single project. Any help will be welcomed!
The question was: How to use different Kotlin versions for different modules in the same project?
I will give an answer how I solved this problem.
Example scenario, there are 2 modules :app and :module.
:app needs to use Kotlin version 1.8.0
:module needs to use Kotlin version 1.6.2
Remove from your top-level build.gradle plugin block:
plugins {
id "org.jetbrains.kotlin.android" version "1.8.0" apply false
}
Add a buildscript block to :app module's build.gradle:
buildscript {
repositories {
gradlePluginPortal()
// mavenCentral() include if you need plugins from other repositories
// google() include if you need plugins from other repositories
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
// other plugin dependencies...
}
}
apply plugin: 'org.jetbrains.kotlin.android'
Add a buildscript block to :module build.gradle and specify kotlin version:
buildscript {
repositories {
gradlePluginPortal()
// mavenCentral() include if you need plugins from other repositories
// google() include if you need plugins from other repositories
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.2"
// other plugin dependencies...
}
}
apply plugin: 'org.jetbrains.kotlin.android'
That's it. Now, you :module will be built using 1.6.2 and :app with 1.8.0