Laur IVAN

Set Different Gradle Configurations

Posted by in IT, Tutorial

TL;DR: create a global gradle.properties file (in <HOME>/.gradle or GRADLE_USER_HOME if defined). Place there the system specific configuration. The other day I had the unpleasant surprise that Android Studio replicated my proxy settings into gradle.properties and got committed to Git. Including a password (which has since became obsolete). Since my other environment doesn’t use a proxy, I got an error there. Now, the question became: How do I create a single project gradle settings file which would allow me to run smoothly in both places? Although I thought of a…read more

Fix Gradle Error: UNEXPECTED TOP-LEVEL EXCEPTION

Posted by in Software

Today I got the lovely UNEXPECTED TOP-LEVEL EXCEPTION from the dexer in android. Looking on the net yielded several causes and resolutions. Note: I’m using Gradle 2.10, Android Studio 2.0.0-beta2 Caching Apparently, sometimes Gradle is shooting itself in the foot with the caching. The first thing you can do is to clean your project. Remove all build directories, all Gradle caches and rebuild. Some references: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException Duplicate inclusion It looks like this is the most common reason for such error. >Duplicate inclusion can occur when your app…read more

Move Gradle Home

Posted by in Software

I’m having some space constraints and I need to move as much as possible to a non-backed-up place. Gradle home (the .gradle directory) has 2.23GB on my computer. A lot, so it must go. The procedure is simple. Just create an environment variable named GRADLE_USER_HOME:

Now all your gradle stuff (e.g .caches) will be dumped there. IMPORTANT! If you have already a gradle.properties with stuff, don’t forget to copy it to the new location! Otherwise, all your niceties will be lost :( HTH, A little experiment: If you find…read more

Gradle(w) and Proxy Authentication

Posted by in Software

The recent updates in Android Studio eliminate the possibility of passing JVM arguments to gradle. That’s quite unfortunate because I quite liked my solution and now I was getting a (not) nice Connection refused message… So I had to find a different solution. Environment Variable As always, everything related to Java can be configured via an environment variable. if you set GRADLE_OPTS, it’ll get passed to gradlew as JVM arguments. My GRADLE_OPTS looks like this now:

You should need to set up the https variants because downloads are made…read more

Android – More Speed up Building with Gradle

Posted by in Software

In my previous post I described one thing you can easily do to improve the build speed, namely enabling the gradle daemon. In the meantime, things improved quite a bit: Gradle 2.4 (at the moment of writing) has better speed You can run things in parallel now like other build tools (e.g. make ) You can use the “configure on demand” feature even though AS complains a bit about it How do you make it work? Here are the steps: Using Gradle 2.4 I’ve enabled gradle 2.4 for my project…read more

Split a Gradle Build File

Posted by in Software

TL;DR: If you can, use ext {} with constants (hash). You can do call pointer things too! In the past days I’ve been trying to add some functionality to my Gradle build file so the version would be determined from the git tag. I’ve found this excellent entry showing how to get the actual string. My code ended up being like this:

Long build file The problem I have is that with every custom thing, the build file increases. Then, finding an error of a particular thing becomes more and…read more

Android java.lang.VerifyError and Boilerplate code

Posted by in Software

TL;DR: Change the java version compatibility in your gradle file (see below) or remove Hugo references from your e.g. “debug” code in Velcro. The other day I discovered a bunch of template-based application generators for android. While they are very interesting and apply some of the best practices, they come with a footnote: Use it at your own risk, particularly if you’re not that familiar with the dependency libraries. So, I’ve started using Velcro as a starting point and was pleasantly surprised of things like Dagger and Hugo and the…read more

Android – Speed up Building with Android Studio and Gradle

Posted by in Software

I’ve noticed that building a small application with gradle is slow (in my case because I’m only starting with Android development and I compile stuff way too often). One of the things I found online was a way to speed up building by using the gradle daemon instead. From daemon’s documentation: […] We came up with several use cases where the daemon is very useful. For some workflows, the user invokes Gradle many times to execute a small number of relatively quick tasks. For example: When using test driven development,…read more

Gradle and Proxy Authentication in Android Studio

Posted by in Software

Update: This is obsolete as Android Studio is going to eliminate JVM arguments for gradle. See this post for a more future-proof approach. The other day I did an exercise to install Android Studio (“AS” henceforth) (0.8.4 at the moment of writing) and create a project with gradle in an environment with an authenticated proxy. It didn’t work out of the box, of course. Worse, it generated an exception (internal error). I found two solutions to make it work: Via configuration file JVM variables Configuration file When you create a…read more