Upgrading to dev15 of Jetpack Compose

Upgrading an existing Jetpack Compose project, running dev14 or earlier, to dev15 is a bit more involved than past updates. Here is what you need to do to move from dev14 to dev15, for a project using traditional Groovy-based Gradle files. If you are upgrading from an older Compose version, or you are using Kotlin Gradle scripts, some modifications will be needed to these instructions.

Step #1: Upgrade Your Kotlin and Compose Versions

Compose now works off of a pre-release version of Kotlin 1.4, and we need to have our projects adapt to that.

In your top-level build.gradle file, you probably have a kotlin_version constant declared, such as:

ext.kotlin_version = "1.3.61"

Change that to point to the 1.4-M3 version instead. That is not available in the standard repositories, so you will need to add https://dl.bintray.com/kotlin/kotlin-eap/ as a Maven repository, both for the buildscript dependencies and for the rest of the modules.

If you have a compose_version constant declared here, set it to point to 0.1.0-dev15.

So, for example, you might wind up with something like:

buildscript {
    ext {
        compose_version = '0.1.0-dev15'
        kotlin_version = "1.4-M3"
    }

    repositories {
        google()
        jcenter()
        maven {
            url "https://dl.bintray.com/kotlin/kotlin-eap/"
        }
    }

    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0-alpha05"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://dl.bintray.com/kotlin/kotlin-eap/"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Step #2: Upgrade the Compose Build

In your modules’ build.gradle files, you should have a composeOptions closure, with something like this:

composeOptions {
    kotlinCompilerExtensionVersion "${compose_version}"
    kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
}

If you have a Compose version hard-coded for kotlinCompilerExtensionVersion, change it to point to 0.1.0-dev15. And, change the kotlinCompilerVersion as well:

composeOptions {
    kotlinCompilerExtensionVersion "${compose_version}"
    kotlinCompilerVersion '1.4.0-dev-withExperimentalGoogleExtensions-20200720'
}

Also, towards the bottom of the build.gradle file, outside of any other closure, add:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
    }
}

It is not completely clear why Google is advising this approach, rather than having this kotlinOptions closure in the android closure. In my experiments, rather than using that tasks.withType() block, I added the kotlinOptions to the android closure:

kotlinOptions {
    jvmTarget = '1.8'
    freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}

One or both of those techniques hopefully will work for your project.

Some developers report also needing to include this in kotlinOptions:

languageVersion = "1.4"

Step #3: Upgrading Your Dependencies

In addition to switching to new Kotlin and plugin versions, the Compose team is in the process of completely refactoring the artifacts used by Compose. You are going to need to switch to the new artifacts to get things to work.

Fortunately, many of the key Compose bits are set up as transitive dependencies of the material artifact:

implementation "androidx.compose.material:material:$compose_version"

The biggest thing not covered by that is the @Preview annotation, which for the time being still resides in:

implementation "androidx.ui:ui-tooling:$compose_version"

However, there are many other artifacts, not all of which are necessarily pulled in by material:

  • androidx.compose.animation:animation:0.1.0-dev15
  • androidx.compose.animation:animation-core:0.1.0-dev15
  • androidx.compose.foundation:foundation:0.1.0-dev15
  • androidx.compose.foundation:foundation-layout:0.1.0-dev15
  • androidx.compose.foundation:foundation-text:0.1.0-dev15
  • androidx.compose.material:material:0.1.0-dev15
  • androidx.compose.material:material-icons-core:0.1.0-dev15
  • androidx.compose.material:material-icons-extended:0.1.0-dev15
  • androidx.compose.runtime:runtime:0.1.0-dev15
  • androidx.compose.runtime:runtime-dispatch:0.1.0-dev15
  • androidx.compose.runtime:runtime-livedata:0.1.0-dev15
  • androidx.compose.runtime:runtime-rxjava2:0.1.0-dev15
  • androidx.compose.runtime:runtime-saved-instance-state:0.1.0-dev15
  • androidx.compose.ui:ui:0.1.0-dev15
  • androidx.compose.ui:ui-geometry:0.1.0-dev15
  • androidx.compose.ui:ui-graphics:0.1.0-dev15
  • androidx.compose.ui:ui-text:0.1.0-dev15
  • androidx.compose.ui:ui-text-android:0.1.0-dev15
  • androidx.compose.ui:ui-unit:0.1.0-dev15
  • androidx.compose.ui:ui-util:0.1.0-dev15

Between the documentation and looking up specific classes at AndroidX Tech, you should be able to identify the new artifacts to use.


With those changes, you can migrate a simple Compose project from dev14 to dev15. Again, the more complex your project, or the further removed from dev15 it is, you may have additional changes that you need to make.