Image credit: Make your build.gradle great again
My team has recently had some interesting build issues. Here's a paraphrased quote from one team member:
I had issue with updating a JAR - project did not see classes because file name was changed. I tried rebuild, removing
/build
folders manually, invalidate caches etc - nothing helped. Then I cleared theuser-home\.gradle\caches
which resolved the issue
And another:
I actually did fix my machine this morning...I deleted all of the
Android\sdk
,user-home\<AS settings path>
,Android Studio
, and.gradle
. Seems like the nuclear option worked 🙂 I swear I did that the other day without luck
It may be worth mentioning that both of these teammates use Windows, while I use Linux, and as such they were basically on their own trying to resolve their build problems.
So what are your experience with building your Android projects? When has Gradle let you down? What do you wish Gradle would do for you?
Discussion (4)
Don't rely on
git
to let you know if your workspace is "clean" There are gradle files you should have ignored by git but can change how your build works. Usegit status --ignored
liberallyDuplicate compile work when using gradle CLI & Android Studio. It's like what even are caches
Gradle & Groovy. Did
make
just set the standard that each new build system requires learning Yet Another LanguageGradle & Java. Builds should be fast. Gradle is not (at least for non-trivial projects). Comparing Android+Android Studio and iOS+Xcode equivalent apps' (as in the same app for the same company with parity) build times is laughable. Xcode is like the time it takes for me to take a sip of my coffee. Android Studio is closer to making a Starbucks run.
Could you elaborate on the first point? I've never run into an issue like that, I think.
Regarding duplicate gradle work with CLI and AS, I totally agree. I blame AS for this, though. It does a lot of "magic" behind the scenes that a gradle command on CLI will not do.
On the Groovy point, I remember being confused when I first made the switch from Eclipse to Android Studio and Gradle. But ultimately I became really happy that I was able to write my build logic with a real language! At least Groovy is a JVM language, so the hurdle isn't as great as it could be. It also helped me a lot when I started writing my unit tests with the Spock framework, which uses Groovy. As annoying as it might be, I'd encourage you to spend the time -- you won't regret it! ALSO, I would be remiss if I didn't point out that we can now write our Gradle scripts in Kotlin, so if you've made that switch in your app dev work, you can now use just one language for both.
What kind of configuration do you do with your gradle scripts? I recently managed to shave ~20s off build times by enabling parallel builds (I had to do a bit of work to decouple my 18 gradle modules first, though).
When I first picked up Android, I really struggled to wrap mind around Gradle. Part of it was that I was still pretty new to build tools in general (I was still in college at the time), but part was also just that Gradle is a very complicated build tool, with a lot going on under the hood.
Not knowing what Gradle was actually doing and how to actually interact with it, not knowing where it keeps its files, etc, was where I would have these similar kinds of issues crop up. I would highly recommend you take some of their online courses. They are very thorough, yet accessible with lots of examples and sample projects; taught live by their own knowledgeable engineers, so you can ask questions and get help directly; and in many cases free. These courses are what took me from barely understanding Gradle at all to being able to create my own complex builds, and debug issues for myself as they came up.
gradle.org/training/
I appreciate the response and the link! I wasn't actually crying out for help, but rather trying to ask the community what their Gradle issues are :) Mainly out of curiosity, but also for responses like this, which hopefully can help others.