Notes on the Jetpack Compose alpha11 to alpha12 Upgrade Process
Upgrading an app from Compose alpha11 to alpha12 was more troublesome thannormal. I took some notes along the way and wanted to pass them along.
Note: all of the Gradle samples show the classic Groovy approach ��� you willneed to tweak those for build.gradle.kts if you are going that route.
The obvious change is moving your Compose Gradle plugin and all of theCompose runtime dependencies to 1.0.0-alpha12, along with your kotlinCompilerExtensionVersionin composeOptions. If you have been working with Compose for a while, this isa standard change, and hopefully you have consolidated all of those versionreferences into a single constant.
Compose alpha12 also requires Kotlin 1.4.30, for its Gradle plugin and forits runtime dependencies. With luck, you have a single constantfor that as well:
buildscript { ext { kotlinVersion = "1.4.30" composeVersion = '1.0.0-alpha12' } ...}The release notesalso show having this Gradle snippet outside of your android {}closure in your modules:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { jvmTarget = "1.8" freeCompilerArgs += ["-Xallow-jvm-ir-dependencies"] }}After doing those things, I then ran into a bunch of IDE errors akin to the following:
���padding(Dp): Modifier��� is only available since Kotlin 1.4.30 and cannot be used in Kotlin 1.4
At first, I tried upgrading to ���Android Studio Arctic Fox | 2020.3.1 Canary 6���(hereafter referred to as ���Canary 6��� for simplicity). That did not clear up the problem.
The solution is to upgrade the Kotlin plugin in the IDE to support 1.4.30. Unfortunately,this is not yet stable. So, you need to:
Open the Settings dialog in Canary 6 Go into ���Languages & Frameworks��� > Kotlin Switch your ���Update channel��� to ���Early Access Preview 1.4.x��� Choose to upgrade your Kotlin plugin to 203-1.4.30-RC-AS6682.9 (or newer, depending on when you are reading this) Restart Android Studio afterwardsThis appears to be undocumented, unless you countKotlinlang Slack messages from Google developersas documentation.
You should also check all your third-party dependencies and make sure that you havetheir latest versions, as otherwise you may fail when you build the module.In my case, I needed to upgrade dev.chrisbanes.accompanist:accompanist-coilto 0.5.1.
That got me to the point where things would run, but you are likely to encountera bunch of deprecations.
The one that will affect most of you is thatsetContent() on Activity will show up as deprecated. That is because it movedout of a mainline Compose dependency. You will need to add:
implementation "androidx.activity:activity-compose:1.3.0-alpha02"to your module���s list of dependencies. Note the alpha02 ��� while alpha01was released this past week, alpha02 shipped hours later to fix a significant bug.
Once you have that dependency in place, you can replace:
import androidx.compose.ui.platform.setContentwith:
import androidx.activity.compose.setContentIf you happen to be using the Jetpack ViewModel in your Compose UI code, you may runinto a similar deprecation notice on viewModel(). That is another case where theextension function moved from a mainline Compose dependency to another one.You will need to add:
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha01"to your module���s dependencies. Then, you can change:
import androidx.compose.ui.viewinterop.viewModelto:
import androidx.lifecycle.viewmodel.compose.viewModelThere is a ���long tail��� of other deprecations that you might encounter. In mysamples, one was that imageResource() is deprecated. The replacements,though, will vary by circumstance:
If you need a Bitmap, you will wind up changing imageResource(R.drawable.whatever)to imageFromResource(LocalContext.current.resources, R.drawable.whatever)
Otherwise, painterResource(R.drawable.whatever) will probably suffice
This upgrade process was more involved than usual, exacerbated by gaps indocumentation. I will be honest: this worries me, with a possible move to ���beta���versions coming in the next couple of weeks.


