My Android Development Environment

This guide describes how to install an operative development environment for creating Android applications. It can be either considered as guidelines or just as a quick list of tools for developers. Anyway, it helps me to sum up steps I have to follow when I am setting up a new computer.

Checking out source code

I like having a workspace directory to contain my configuration files and projects. This directory has to be organized with the use of sub-directories. You can create a workspace wherever you want but I like to create my workspace in the ${HOME} environment for quicker access from my terminal.

mkdir ~/Workspace

Oh My Zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. You can install it by running the following commands in your terminal :

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Android Studio

Installing Android Studio is straightforward using this link. But you have to make sure to export ANDROID_HOME to your environment variables.

# Android SDK
SDK=${HOME}/Library/Android/sdk
SDK_PLATFORM=${SDK}/platform-tools
SDK_TOOLS=${SDK}/tools
export PATH=${PATH}:${SDK}:${SDK_PLATFORM}:${SDK_TOOLS}
export ANDROID_HOME=${SDK}

With this, you are able to use adb or any other android tools such as screenshot2, lint, hierarchyviewer from your terminal.

Copyright header

The source code I produce belongs to my company. These sort of ‘license headers’ are designed simply to alert someone who happens upon a file that they should not distribute it.

  • Go to Android Studio Preferences > Editor > File and Code Templates
  • Select Includes tab and remove File header content
  • Then, go to Android Studio Preferences > Copyright > Copyright profiles
  • Create a new profile
Copyright (c) $today.year, renaudmathieu.fr
All rights reserved.
  • Go to Android Studio Preferences > Copyright and select your new profile as the default project copyright

Plugins

Go to Android Studio Preferences > Plugins and install the following plugins:

Auto Save

This plugin helps me to follow Android field naming conventions, automatically organize imports and reformat my code. It’s a quick setup (so it’s easy to ask your colleagues to install it ^^) and it brings a clean code for everyone in the team.

  • Once Auto Save has been installed, you need to restart Android Studio.
  • Then, go to Android Studio Preferences > Other Settings > Save Actions
  • Ensure Activate save actions, Organize import and reformat code is checked
  • Finally, ensure you Reformat only changed code (Checking Rearrange code can be useful for Android XML Layout files)
  • Once Auto Save has been installed, you need to restart Android Studio.
  • Go to Android Studio Preferences > Editor > Code Style > JAVA
  • Select the tab Code Generation, in the naming > name prefix, put “m” for the Field

Android Material Design Icon Generator Plugin

This plugin helps you to set material design icons to your Android project. Don’t ask your designer, use them directly.

Android Butterknife Zelezny

It’s a simple plug-in for Android Studio/IDEA that allows one-click creation of Butterknife view injections.

Terminal

Scripts

.gitignore

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
.project
build/
/*/build/
reports/

# Idea files
*.iml
.idea/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Apple files
.DS_Store

pidcat

During application development you often want to only display log messages coming from your app. Unfortunately, because the process ID changes every time you deploy to the phone it becomes a challenge to grep for the right thing.

This script solves that problem by filtering by application package. Supply the target package as the sole argument to the python script and enjoy a more convenient development process.

brew install pidcat
pidcat com.renaudmathieu.beta

Aliases

alias log="pidcat com.renaudmathieu.beta"

# Git
alias repo_clean="git remote update origin --prune && git branch --merged development | grep -v development | xargs git branch -d"
alias repo_check="git for-each-ref --sort=committerdate --format='%(refname:short) * %(authorname) * %(committerdate:relative)' refs/remotes/ | column -t -s '*'."
#git diff --name-only checkstyle $(git merge-base checkstyle development) # Get modified files in a branch

# Android
alias adbclear="adb shell pm clear com.renaudmathieu.beta"
alias adbactivities="adb shell dumpsys activity | grep -i 'run' | grep -i 'com.renaudmathieu.beta'"