DEV Community

Cover image for Matt's Tidbits #61 - Getting out of a dependency cycle
Matthew Groves
Matthew Groves

Posted on • Originally published at Medium

Matt's Tidbits #61 - Getting out of a dependency cycle

Last week I wrote about a neat way to cleanly handle null values in Kotlin. This time, I have another story related to more lint errors after upgrading the Android Gradle Plugin to 3.6.1.

As I wrote previously in Tidbits #59 and #58, version 3.6 of the Android Gradle Plugin has caused some unexpected issues - more than you might normally expect to see when upgrading your build tools.

Unfortunately, I ran into some additional issues this week that I wanted to share, in the hopes that you might avoid falling into the same traps!

The first link in the dependency cycle was the following lint issue:

In older versions of the Android Gradle Plugin (such as 3.5.3), Android Studio flags this as a warning, but the lint tool doesn't flag this. However, beginning in AGP 3.6, this is now flagged as an error, so if you use lint in your CI system (as we do), your build will fail.

The first thing I tried was upgrading to the latest version of Butterknife - unfortunately this did not resolve the issue.

The next thing we tried to resolve this was upgrading our version of Gradle (separate from AGP) from 5.6.4 to the latest - 6.2.2. Interestingly, this caused the lint error to go away!

However - upgrading to the latest version of Gradle broke an in-house static analysis library we're using - for some reason, it could no longer locate FindBugs. Digging into this some, I found that the inclusion of FindBugs is no longer recommended, as it has been deprecated and replaced by SpotBugs.

Additionally, as of version 6, Gradle no longer includes FindBugs (because it doesn't support Java 9/10/11, etc.), which explains why our in-house library was now failing to build.

I then attempted to migrate the library to use SpotBugs, but unfortunately that proved to be much more than a quick fix - this library was apparently not just using the stock version of FindBugs, but instead a special one that had been bundled with Gradle.

So, I found myself fairly stuck - I had a lint error that I really wanted to go away, and had only appeared after upgrading AGP (because I wanted a different warning to go away), but I couldn't upgrade to Gradle 6+ because that broke another library that we used. Ack!

I ended up posting a message on my team's Slack and thankfully, one of my coworkers dug up the following issue filed against butterknife:
https://github.com/JakeWharton/butterknife/issues/1593

It had always seemed strange that there was a lint issue when importing Butterknife at all, as we were following Butterknife's instructions exactly. Now we had proof (from Jake Wharton!) that perhaps we were the victims of a bug.

I did some more digging and came across this issue in Android Studio's bug tracker: https://issuetracker.google.com/issues/140881211

This was the confirmation I needed! Unfortunately this issue won't be fixed for a while (Android Studio 4.0), but, finally we found the issue - a single line of code that erroneously identifies Butterknife's dependency as an annotationProcessor.

Given all of the above, the solution ended up being really simple:

// Lint issue ignored due to bug in Android Studio:
//  https://issuetracker.google.com/issues/140881211
//noinspection AnnotationProcessorOnCompilePath
implementation "com.jakewharton:butterknife:10.1.0"
Enter fullscreen mode Exit fullscreen mode

...just ignoring the lint warning!

The important things to remember here are:

  1. If you get stuck in a dependency cycle, try to evaluate all of your options to see if there's an easier way to break out of it. Sometimes you may have to bite the bullet and tackle a more major project, but we all have deadlines, and sometimes you just don't have the time right now.
  2. If you upgrade to AGP 3.6.1, prepare for the fact that you might experience some problems!
  3. If you notice strange/regressive behavior, always search for bug reports in the tools you're using (Butterknife, Android Studio, etc.) to see if other people are experiencing the same problem. If they are, perhaps someone else has already done the hard work and identified exactly what's wrong (and maybe has already fixed it).
  4. Ask for help and do some internet research before you spend too much time spinning your wheels - knowledge is power!

I hope you learned something helpful from this! Have you noticed other strange issues with AGP 3.6.1? Please let me know in the comments if you have - I'd love to hear about it! 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 discovered on March 19, 2020.

Top comments (0)