Hi everyone :wave: I am working on migrating an e...
# android
s
Hi everyone 👋 I am working on migrating an existing android project to compose and followed the official guideline for dependencies (kotlin, agp etc). This is what my root gradle looks like,
Copy code
ext {
        compose_version = '1.0.1'
        kotlin_version = '1.5.21'
        agp_version = '4.2.2'
    } 
    dependencies {
        classpath "com.android.tools.build:gradle:$agp_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
compose dependencies
Copy code
implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation "androidx.compose.compiler:compiler:$compose_version"
    implementation 'androidx.activity:activity-compose:1.3.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
It fails while compiling saying `this version (1.0.1) of the Compose Compiler requires Kotlin version 1.5.21 but you appear to be using Kotlin version 1.4.31 which is not known to be compatible. Please fix your configuration (or
suppressKotlinVersionCompatibilityCheck
but don't say I didn't warn you!).` Any hints where
Kotlin 1.4.31
might be coming from?
this is my android plugin
Copy code
android {
    compileSdkVersion 30

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
        useIR = true
    }

    defaultConfig {
        applicationId = "com.dummy.testapp"
        minSdkVersion 21
        targetSdkVersion 30

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
        }

        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '<http://sample-proguard-rules.pro|sample-proguard-rules.pro>'
        }
    }

    flavorDimensions "default"


    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
    }

    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}
X-posting in compose channel..
s
migrate to agp 7.0.3
☝️ 1
s
oh is that a requirement for starting with compose? I am afraid it’s going be a bigger change for us. AGP 7.0 and JDK 11
Tried to bump kotlin to 1.5.31 and supported compose version, https://developer.android.com/jetpack/androidx/releases/compose-compiler#1.0.4 but it blows up with another error during Kapt stub generation blob shrug
Copy code
> Task :sample:kaptGenerateStubsDemoDebugKotlin
Could not perform incremental compilation: Could not connect to Kotlin compile daemon
Could not connect to kotlin daemon. Using fallback strategy.
exception: java.io.EOFException
	at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:3244)
	at java.io.ObjectInputStream$BlockDataInputStream.readUTFChar(ObjectInputStream.java:3645)
	at java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(ObjectInputStream.java:3542)
	at java.io.ObjectInputStream$BlockDataInputStream.readUTF(ObjectInputStream.java:3342)
	at java.io.ObjectInputStream.readUTF(ObjectInputStream.java:1203)
	at org.jetbrains.kotlin.utils.PluginUtilsKt.decodePluginOptions(pluginUtils.kt:39)
	at org.jetbrains.kotlin.android.synthetic.AndroidCommandLineProcessor.processOption(AndroidComponentRegistrar.kt:91)
	at org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParserKt.processCompilerPluginsOptions(PluginCliParser.kt:125)
	at org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser.processPluginOptions(PluginCliParser.kt:83)
	at org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser.loadPlugins(PluginCliParser.kt:72)
	at org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser.loadPluginsSafe(PluginCliParser.kt:44)
	at org.jetbrains.kotlin.cli.common.CLICompiler.loadPlugins(CLICompiler.kt:179)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:69)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:76)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:45)
	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:227)
	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:222)
	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:214)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:271)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
f
you need to use this versions
Copy code
ext {
    ext.kotlin_version = '1.5.31'
    ext.compose_version = '1.1.0-beta02'
}
and add this
Copy code
buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion compose_version
}
in app build.gradle
s
thanks @Frédéric Lemieux, I already have the
compose true
and
kotlinCompilerExtensionVersion compose_version
. Regarding the compatible versions, how did you find it? is it just trial and error because none of the config on official guide seem to work.
f
I found it in one project on github
and it fixed this issue for me
s
hmm it requires me to have
targetSdkVersion 31
🤔