\textit{}%
%   Copyright 2013 Katarzyna Szawan <kat.szwn@gmail.com>
%       and Michał Rus <m@michalrus.com>
%
%   Licensed under the Apache License, Version 2.0 (the "License");
%   you may not use this file except in compliance with the License.
%   You may obtain a copy of the License at
%
%       http://www.apache.org/licenses/LICENSE-2.0
%
%   Unless required by applicable law or agreed to in writing, software
%   distributed under the License is distributed on an "AS IS" BASIS,
%   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%   See the License for the specific language governing permissions and
%   limitations under the License.
%

\section{Introduction}
\label{sec:impl-intro}

\subsection{Choosing IDE}
\label{subsec:choosing-ide}
We started with setting up a development environment. Since our language of choice is Scala, it was important to find an IDE which provides support for both Android and Scala development and can integrate these two elements. Quickly, it turned out that there is no out-of-the-box solution. Three most popular development environments are Ecplise, NetBeans and IntelliJ, and all of them support Scala development. 

After some research and because of previous experience with Android development, we decided to work in IntelliJ IDEA 12 (and we switched to 13 as soon as it was released). We chose this particular solution because it provides seperate module facets for Android and Scala projects~\cite{Steingress:2011:AndroidScala}. Also, it seems that it is the most advanced tool when it comes to code assistance. One of its most helpful features is smart code completion for both Scala- and Android-specific files~\cite{Steingress:2011:AndroidScala}. Also, IntelliJ IDEA offers a great deal of code analysis tools, which help to locate possible bugs, dead code and performance issues. The whole process of compiling a project is sped up by external build (it means that all compilation tasks are run as a process separated from other IDEA processes). Apart from speeding the compilation up, this decreases IDE's memory consumption~\cite{Fatin:2012:NewWay}. The latest version (13) has built-in SBT (Simple Build Tool) integration (this term will be explained in \cref{subsec:android-sbt}).

\subsection{Is developing for Android in Scala a good idea?}
\label{subsec:good-idea}
Developing Android applications in Scala has recently become more and more popular. However, there is a number of possible problems that a developer can meet. One of the most important drawbacks is that the building is significantly slower than this of a regular Java application. It is due to the fact, that Scala's standard library need to be converted to Dalvik (Android's virtual machine) bytecode during the build process. There are many ways to make building faster, for example using ProGuard with cache turned on. It shrinks and optimizes code also remembering the optimisations, thus making it smaller and faster~\cite{Berkel:2011:preinstall}. Another way is to preload Scala dexed (JVM bytecode translated to Dalvik bytecode) libraries on the Android device and add them to the Android runtime, which eliminates the need to do it during the build process~\cite{Berkel:2011:preinstall}. However, it requires access to a root account on the device, which is usually not provided in stock Android ROMs. Moreover, rooting Android devices involves taking certain actions which most often leads to voiding the warranty.

\subsection{Android integration with SBT}
\label{subsec:android-sbt}
Since, as mentioned, there is no out-of-the-box solution for Android development in Scala, we had to find an SBT plugin which integrates both modules and makes the build process as fast as possible. SBT is an open source build tool for Scala and Android projects similar to Maven or Ant (but when writing the build files, one actually uses... Scala itself). It is used to invoke Scalac compiler, which compiles the source code to the JVM bytecode. One of the main reasons why it is so popular is that it provides an interactive shell---the REPL (Read--Eval--Print Loop)---from which one can freely access all classes of the project. Another is incremental compiling, thanks to this feature only modified files are recompiled~\cite{Fatin:2012:NewWay}. A way to extend SBT's functionality is using one of the many available plugins, or writing one. For example, to set-up a project in IntelliJ, we used sbt-idea plugin, which generates Android IntelliJ IDEA project configuration files directly from SBT.

When it comes to Android integration, at first we used an Android--SBT plugin co-written by Walter Chang, Mark Harrah and Jan Berkel, available on github.com as `android-plugin' repository. It provides full IntelliJ support and automatic preloading of Scala library on both emulator and rooted device, which means that using ProGuard is not needed. However, it requires the installation of conscript, g8 and cloning a template project which has lots of autogenerated configuration~\cite{Nguyen:2013:differences}.

Due to this and few other reasons we decided to switch to another SBT plugin written by Perry Nguyen, available on github.com as `android-sbt-plugin' repository. It turned out to be significantly faster than Jan Berkel's plugin, which was also more difficult to use, and enforced an SBT-style project layout~\cite{Nguyen:2013:differences}.
