loading...
Cover image for Matt's Tidbits #58 - A strange issue when upgrading to Android Studio 3.6

Matt's Tidbits #58 - A strange issue when upgrading to Android Studio 3.6

mpeng3 profile image Matthew Groves Originally published at Medium ・3 min read

Matt's Tidbits (42 Part Series)

1) Matt’s Tidbits #35 - A strategy for debugging complex unit test failures 2) Matt’s Tidbits #36 - How to get complete code coverage in unit tests for a nullable Kotlin “var” 3 ... 40 3) Matt's Tidbits #37 - How to run apps on multiple devices simultaneously! 4) Matt's Tidbits #38 - An elegant way of dealing with RxLifecycle lint warnings 5) Matt’s Tidbits #39 - Why writing tests is so important 6) Matt's Tidbits #40 - RxJava doOnSubscribe() behavior explained 7) Matt's Tidbits #41 - Converting a BehaviorRelay into a PublishRelay 8) Matt's Tidbits #42 - The answer to the Ultimate Question of Life, the Universe, and Everything… 9) Matt's Tidbits #43 - Making the most of your phone’s sensors 10) Matt's Tidbits #44 - How to take great screenshots on Android 11) Matt's Tidbits #45 - Creating a private token class 12) Matt's Tidbits #46 - Scratch files 13) Matt's Tidbits #47 - Finding list items by title in Espresso 14) Matt's Tidbits #48 - Separating out search results for test code 15) Matt's Tidbits #49 - What to do when your (Log)cat misbehaves 16) Matt's Tidbits #50 - How to (inadvertently) initialize a Kotlin val twice 17) Matt's Tidbits #51 - Easy stack traces 18) Matt's Tidbits #52 - Formatting etiquette 19) Matt's Tidbits #53 - First year in review 20) Matt's Tidbits #54 - Caches, deployments, and IT - oh my! 21) Matt's Tidbits #55 - Strange Breakpoint behavior with Rx schedulers 22) Matt's Tidbits #56 - Be careful with @JvmOverloads 23) Matt's Tidbits #57 - Improving RxJava stack traces 24) Matt's Tidbits #58 - A strange issue when upgrading to Android Studio 3.6 25) Matt's Tidbits #59 - Unexpected new lint failures 26) Matt's Tidbits #60 - Cleanly handling null values in Kotlin 27) Matt's Tidbits #61 - Getting out of a dependency cycle 28) Matt's Tidbits #62 - When you're feeling exhausted... 29) Matt's Tidbits #63 - Some good news about AGP 3.6.2 30) Matt's Tidbits #64 - Digging into some Ham...crest assertions 31) Matt's Tidbits #65 - It's time for proper support for JUnit 5 32) Matt's Tidbits #66 - The magic of Kotlin's "reified" keyword 33) Matt's Tidbits #67 - Some tips for working from home 34) Matt's Tidbits #68 - Testing RxJava Observables 35) Matt's Tidbits #69 - Neat Kotlin field tricks 36) Matt's Tidbits #70 - Cleaner diffs! 37) Matt's Tidbits #71 - Trying to figure out what to say 38) Matt's Tidbits #72 - Migrating from RxJava 2 -> 3 39) Matt's Tidbits #73 - Deciding which Kotlin scope function to use 40) Matt's Tidbits #74 - Resolving an interesting Kotlin <-> Java interop issue 41) Matt's Tidbits #75 - Moving tidbits! 42) Matt's Tidbits #76 - A long-overdue feature

Last time I wrote about how to improve RxJava stack traces. This week, I want to highlight a potential issue you may run into when upgrading to Android Studio 3.6.

Android Studio 3.6 launched on February 24, and brings a number of updates. You can read more about them here: https://android-developers.googleblog.com/2020/02/android-studio-36.html

Always one to keep my software as up-to-date as possible, I downloaded the update and installed it. So far, the IDE is working great! However, as usually happens when there’s a new release of Android Studio, there’s also an update to the Android Gradle plugin.

You have almost certainly seen this dialog box pop up before:

I despise annoying pop-ups, so I clicked the update button. Android Gradle Plugin updates are usually safe!

However, what I discovered is that my code would no longer compile!

The Java code that wouldn’t compile looked like this:

public class MyWorker extends Worker {...}

The compiler was complaining that Worker’s constructor has 2 arguments, and my code isn’t specifying either of them. What is going on here?

I double-checked, and the only change had indeed been moving the Android Gradle Plugin version from 3.5.3 to 3.6. I found the library import for the Worker class, and it was this:

implementation "android.arch.work:work-runtime:1.0.0-alpha05"

So, I pulled up the documentation for that version of the Worker class, and everything looked fine. However, I also noticed that this version of the WorkManager library is over a year-and-a-half old — the newest version is 2.3.2! Version history for this library is here: https://developer.android.com/jetpack/androidx/releases/work

I dug in a little more and ran the gradle app:dependencies command to see what my dependencies were, and sure enough, both the older work-runtime library as well as androidx.work:work-*:2.0.0 was also listed. Oddly enough, it was listed as a top-level dependency.

Most importantly, in this newer version of the library, the API for the Worker class has changed, and will no longer compile.

The pieces all fell into place — the latest Android Gradle plugin (3.6) has a dependency on a newer version of the WorkManager library, and because of how my Gradle configuration was set up, this newer version overwrote my older one!

To complete the research, I downgraded back to Android Gradle Plugin 3.5.3 and found that the same version I had been including (1.0.0-alpha05) was included as a top-level dependency. So, my guess is that the Android Gradle Plugin itself had been using WorkManager, and the new version has upgraded to the newer version, leaking that dependency into my app.

I spent a short amount of time trying to figure out how to get that dependency to go away (or to force it to use my older version), but decided this wasn’t worth it, and we should just upgrade — we had been using an alpha version anyways!

I hope you learned something that saves you a little time when upgrading to Android Gradle Plugin 3.6! If you’re a Gradle wizard, how would you have resolved this? Let me know in the comments below! And, please follow me on Medium if you’re interested in being notified of future tidbits.

Interested in joining the awesome team here at Intrepid? We’re hiring!

This tidbit was delivered on February 28, 2020.

Matt's Tidbits (42 Part Series)

1) Matt’s Tidbits #35 - A strategy for debugging complex unit test failures 2) Matt’s Tidbits #36 - How to get complete code coverage in unit tests for a nullable Kotlin “var” 3 ... 40 3) Matt's Tidbits #37 - How to run apps on multiple devices simultaneously! 4) Matt's Tidbits #38 - An elegant way of dealing with RxLifecycle lint warnings 5) Matt’s Tidbits #39 - Why writing tests is so important 6) Matt's Tidbits #40 - RxJava doOnSubscribe() behavior explained 7) Matt's Tidbits #41 - Converting a BehaviorRelay into a PublishRelay 8) Matt's Tidbits #42 - The answer to the Ultimate Question of Life, the Universe, and Everything… 9) Matt's Tidbits #43 - Making the most of your phone’s sensors 10) Matt's Tidbits #44 - How to take great screenshots on Android 11) Matt's Tidbits #45 - Creating a private token class 12) Matt's Tidbits #46 - Scratch files 13) Matt's Tidbits #47 - Finding list items by title in Espresso 14) Matt's Tidbits #48 - Separating out search results for test code 15) Matt's Tidbits #49 - What to do when your (Log)cat misbehaves 16) Matt's Tidbits #50 - How to (inadvertently) initialize a Kotlin val twice 17) Matt's Tidbits #51 - Easy stack traces 18) Matt's Tidbits #52 - Formatting etiquette 19) Matt's Tidbits #53 - First year in review 20) Matt's Tidbits #54 - Caches, deployments, and IT - oh my! 21) Matt's Tidbits #55 - Strange Breakpoint behavior with Rx schedulers 22) Matt's Tidbits #56 - Be careful with @JvmOverloads 23) Matt's Tidbits #57 - Improving RxJava stack traces 24) Matt's Tidbits #58 - A strange issue when upgrading to Android Studio 3.6 25) Matt's Tidbits #59 - Unexpected new lint failures 26) Matt's Tidbits #60 - Cleanly handling null values in Kotlin 27) Matt's Tidbits #61 - Getting out of a dependency cycle 28) Matt's Tidbits #62 - When you're feeling exhausted... 29) Matt's Tidbits #63 - Some good news about AGP 3.6.2 30) Matt's Tidbits #64 - Digging into some Ham...crest assertions 31) Matt's Tidbits #65 - It's time for proper support for JUnit 5 32) Matt's Tidbits #66 - The magic of Kotlin's "reified" keyword 33) Matt's Tidbits #67 - Some tips for working from home 34) Matt's Tidbits #68 - Testing RxJava Observables 35) Matt's Tidbits #69 - Neat Kotlin field tricks 36) Matt's Tidbits #70 - Cleaner diffs! 37) Matt's Tidbits #71 - Trying to figure out what to say 38) Matt's Tidbits #72 - Migrating from RxJava 2 -> 3 39) Matt's Tidbits #73 - Deciding which Kotlin scope function to use 40) Matt's Tidbits #74 - Resolving an interesting Kotlin <-> Java interop issue 41) Matt's Tidbits #75 - Moving tidbits! 42) Matt's Tidbits #76 - A long-overdue feature

Posted on by:

mpeng3 profile

Matthew Groves

@mpeng3

Software engineer with 10+ years of professional experience in C++, C#, Java, and Kotlin.

Discussion

markdown guide