Category Archives: Android

Posts on Android development

Gradle build file for a project with Android Annotations

There is a sample Gradle build file for a project with Android Annotations. This is pretty complicated stuff, that was achieved with a lot of my blood, so I decided to post it here, so that you can use it to try to find your mistakes. Android Annotations library is loaded with apt. The position of every setting is important. There is also a trick to avoid Lint errors and a custom task to run app via command line.

I used Gradle 1.12 and Android Studio 0.8.4 with Android SDK 20, Android Build Tools 20.0 and Android Plugin 0.12.+.

Running Android app on device using Gradle

Here I will show you, how I managed to build and run an Android app via command line (Terminal, since I use Mac) using Gradle and how I start a resulting app on the device (Google Nexus 5 with Android 4.4.2) automatically. I had to solve two major problems to achieve this.

The first problem is with Gradle version: last version of Gradle is not compatible with the last version of Android Plugin.
The second problem is with custom task to run app on device: you have to put the correct package and activity names.

The final result looks like this:

Where Multiverse is the root folder of my project and the name of the project, appStart – custom Gradle task that builds and runs an app on device.
Gradle loads all dependencies, builds app, makes a lint check and starts and app on your device automatically. Yahoo! This is how it looks on Terminal:

However, I should notice, that this works slower than just running via Eclipse: as you see it takes at least 13 seconds for a little project on Macbook Pro Retina Display Late 2012.

First of all you need to install a correct version of Gradle. If you just download the latest version, your Android plugin will not work. You have to get a version, for instance, 1.10, not 2.0. Also you need to setup PATH variable, so that you will have bin folder of Gradle and android sdks tools there:

Then I created a gradle build file:

Here com.alwawee.multiverse is the package name of the application.
And com.alwawee.main.MainActivity is the full Activity name, that the application starts from. This is how my project tree looks like:
Снимок экрана 2014-07-28 в 1.51.29

This is a part of the Manifest file:

At the end there is a custom task appStart. It is important to correctly write the package name before class name. I thought that the package name is the package name for MainActivity class. I was wrong. It’s a name for a whole app’s package name. You can find it at the root node of your Manifest file.

Notes on commented code: use abortOnError false if you have any serious problems with lint and don’t want to solve them. Uncomment the line about Windows, if you use Windows.

This is a StackOverflow question, I asked to reach this goal.

Installing Gradle on Windows

At first, when I looked at a Gradle distribution, I thought, that it works only on Unix. But then after one search I understood that it works on Windows as well, of course. Here I will describe, how I installed it and set up environment variables with some illustrations step by step.

1. Download current stable release of Gradle from it’s main site, downloads page. It is about 40 Mb in size if you download without source files.


2. Add gradle to PATH variable in My Computer / Properties / Advanced / Environment variables.



3. Check java and gradle versions in Command Line.
Java version

Gradle version

Open-Source Android and iOS Projects

I highly recommend you to look at popular open-source projects in your field even before you start developing something. Because almost everything you want to create is already created by the community with a very high quality. I understood this a year ago when I discovered Open source in iOS for myself and now I discovered it in Android. In this post I will give you a MUST look list of references and projects.

A list of important and popular open-source projects on GitHub for Android and iOS can be found here:

By best match:



By most stars:



By most forks:



How to add shortcut to Home screen in Android programmatically

I improved a little bit a solution that was found in StackOverflow. Now program saves in preferences whether a shortcut was already added and doesn’t add it in new launches of an app if user deleted it. This also saves a little bit time, since the code to add an existing shortcut doesn’t run anymore.

In Android Manifest:

Open-Source Expandable Selection Tree for Android

Today I have published a new open source project on GitHub, called DKExpandableSelectionTree. It is a better expandable list view for Android that allows user to select multiple items from a tree of objects. You can clear all selections, you can select and deselect multiple items by selecting a whole group. It also displays a number of selected items inside a group in parentheses after the name of a group.

This is how it will look in a sample project, when you clone the repository and run it:

This is how it looks in my project:

Mobile App Release Roadmap / Checklist

Mobile App Release Checklist

1. Install new version above the old one.

2. Install your app to different devices, as many as you can (iPad, iPhone, iPhone 5, iPhone 3GS, Galaxy S4, Google Nexus 5, Nexus 3, very small screen size Android devices, etc.) Particularly, for Android and for iPad.

3. Check different geo locations, for example, Moscow, St. Petersburg, Ufa, etc., not the only one, where you live and develop the app.

4. Check that your app doesn’t load data to Documents folder, that is backed up in iCloud. All files should be marked as not backed up, if they can be downloaded again.

5. Check that your app doesn’t have iPad or iPhone words in the name.

6. Check, how data absence is handled when your app fails to load data from server. Particularly, on Android.

7. Check, how bad answers are handled, like HTML instead of JSON. Particularly, on Android.

8. Check, how bad objects in JSON are handled (like null objects or strings instead of objects, etc.). Particularly, on Android.

9. If you use In-App Purchases, check that they are activated for a new version in iTunes Connect.

10. If you use In-App Purchases, check that your app has in-apps if they are activated.

11. Check, how absence of internet is handled.

12. Check, how different operations with arrays and dictionaries are handled.

I am tired of being unsuccessful while releasing new versions of the apps to the AppStore and created a checklist. Always, I forget something to check, when I release an update. Hope, this will save your time, when you publish your app versions. Using the help of testers doesn’t improve final results in these cases, so you have to check all this shit yourself.

All these reasons in my developer experience created some shit in my life. And all these points have their own graves of my time. Check them all, when you decide to release your app version.

Android Animation one after other

I wrote about a new approach to animate multiple objects in Android one after another. For example, 6 ImageButtons and 6 TextViews. I decided to duplicate this solution in my blog.

My approach to reach this goal can be useful when you need to animate a lot of views one after another. You can use setStartOffset method to set a delay before animation begins. So, if you know, how much time will take for your first animation to end, you can set this as a delay for your second animation. This is an example where I animated six ImageButtons and six TextViews below them one after another:

In my res/anim folder I have a file, called fade.xml with these contents:

Here is this post and two other approaches – using AnimationSet and using listeners.