A preview of Android Studio 2.0
The official development tools for Android apps the have gone through some significant changes over the past few years. Originally, a version of Eclipse with a plugin for Android development (which is typically done in Java), called Android Developer Tools (ADT), was Google's official choice for an integrated development environment (IDE). However, that option will be abandoned by the end of this year. In May 2013, a new Java IDE, Android Studio, was announced at the Google I/O developer conference. Android Studio has since become the recommended option for Android developers. With a 2.0 preview unveiled in November, and given that the Eclipse-based alternative will soon cease to be a feasible alternative, it is a good time for an overview of the tool.
![[Editor]](https://static.lwn.net/images/2015/astudio-editor-sm.png)
As with other sophisticated IDEs, Android Studio comes with many features to simplify the process of writing code. There's syntax highlighting for better readability. Another feature is smart rendering, which checks for certain rendering errors, such as a failure to specify dimensional attributes in graphical layouts, and provides a button to press that automatically fixes the error. There is also message filtering, which helps developers locate error messages in build results.
Developers can also annotate sections of source code to flag them for code inspection tools, which is great aid to help catch errors. Those familiar with using the open-source IntelliJ IDEA IDE to write Java code will find themselves right at home; Android Studio is based on IntelliJ IDEA, and inherits the keybindings for coding shortcuts, like pressing Ctrl + D to copy source code quickly.
In general, working with Android Studio gives a developer a feel of a "one-stop-shop" for getting Android development done. It is fast, with visual and other tools that one couldn't find in a text editor or another Java IDE that is not geared toward Android development. For example, a developer can drag and drop "widgets", such as buttons or a progress bar, to a virtual Android device, and the necessary changes will appear in the appropriate XML file.
To facilitate making consistent user interfaces for different devices, which have considerable variance in screen size and resolution, Android Studio uses "density-independent pixel" ("dp") as a unit of measurement. One dp is equivalent to one pixel on a 160-dpi screen, like the 3.5 inch screen with 480 x 320 resolution on older phones. So if a developer were to specify in an XML file that the width of a form field is 100 dp, it would be 100 pixels long on the older phone, but 300 pixels long on the 480 dpi Nexus 5. This built-in support for density independence is a crucial feature for Android developers.
There's a number of APIs that developers can work with to make use of all of the features of a mobile Android device. Extensive documentation of them is available online; simply clicking on a line of code and pressing Ctrl + Q will pop-up relevant documentation within the IDE. Additional APIs are available through the SDK Manager and some, like Google Play Services, are essential to publishing apps on proprietary Google Play Store.
Android has sophisticated APIs for working with OpenGL, which include methods and classes for essential elements like defining and drawing shapes, applying projection, and adding motion. Developers can get started quickly by adding a view container, which serves as the foundation for working with graphics in Android app development.
Being able to write code is only one part of a good development
environment; an IDE must also be able to account for the testing and
debugging needs of developers. This is where the built-in Android Device
Monitor fits in. The monitor is full of testing features, like the Dalvik Debug
Monitor Server "which provides port-forwarding services, screen
capture on the device, thread and heap information on the device, logcat,
process, and radio state information, incoming call and SMS spoofing,
location data spoofing, and more
". The monitor also has a GPU
monitor to see
how demanding an app is on a device's GPU, and a network monitor to
analyze the network activity of the device while it is running the app.
After installing the IDE (builds for Linux, Windows, and Mac OS X can be downloaded here) one begins a project by clicking "Start a new Android Studio project". Then the developer chooses a name for the application and a "Company Domain" name. The domain is used as a fingerprint to distinguish an app from another app with the same name on an app store, like the proprietary Google Play App Store. One can also publish Android applications in other ways, such as via the free-and-open-source software only F-Droid repository. The Company Domain appears as the inverse of a domain name. The package name will then be the Company Domain with the application name appended; for example, com.johndoe.dinnerrecipes.
![[Form factors]](https://static.lwn.net/images/2015/astudio-factor-sm.png)
Before writing a single line of code, a developer must choose which platform to target: "Phone and Tablet" for the traditional Android market; "Wear" for wearable devices such as the Motorola Moto 360 smart watch; "TV" for smart televisions; "Android Auto" for mobile devices connecting to the head unit of an officially compatible automobile; and "Glass" for the head-mounted Google Glass display. While production on Glass has been halted for almost a year, Google does plan to release another version of the product in the future.
For the first three options, the developer must pick a minimum API level
to target. Picking a more recent API will allow access to more features,
but will prevent running
the application on older version of Android. The default minimum for "Phone
and Tablet", targeting
Android 4.0.3 and later, "will run on approximately 96.2% of the
devices that are active on the Google Play Store
", according to the
program (see screen shot at right).
After the target platform, one chooses whether or not to add an
"Activity", which
is an application section that will "provide a screen with which users
can interact in order to do something, such as dial the phone, take a
photo, send an email, or view a map
". Adding an Activity inserts the
relevant base source code into the new project, simplifying initial
work. This leads to the project itself where coding is done. After
adding some code, a developer can compile it into an .apk file
and load it onto an Android device to test it out, or use the built-in
emulator to see how it runs.
The formerly sluggish emulator, which used to be one of the pain points of using Android Studio, is now much faster in 2.0 thanks to optimizations made by Google's developers. It's also full of new features, like being able to resize the emulated Android device on the fly, rotate the screen, as well as to spoof GPS locations, text messages, battery energy levels, and more.
The other major improvements in Android Studio 2.0 are: Instant Run, a GPU Profiler, and improved build times. Instant Run allows editing a project's source code or media assets while the application is running in the Studio emulator and to see the changes immediately with the push of a button. The GPU Profiler, which is still in an early stage, lets one optimize OpenGL ES development to make the best use of an Android device's GPU. Finally, the first build of a project's source code will be at least twice as fast as before, thanks to Google's focus on speed improvements in its Gradle-based build system. These changes will be welcome to Android developers looking to speed up their workflow. More technical details can be found by watching the keynote video announcement [YouTube].
While the project does encourage outside contributions, the only ones with commit privileges are Google employees; Android Studio, as with the wider Android Open Source Project (AOSP), remains very much a Google project. Those wanting to contribute can find instructions on the "Contributing" page, and can submit bug reports at this link. A somewhat active discussion for those working with Android Studio and other official Google Android development tools can be found at a Google Groups forum. Extensive training documentation on how to use Android Studio can be found on an official web page that includes links to articles on how to learn to develop Android applications, as well as links to free online courses from the online educational company Udacity. Android Studio is licensed under the Apache 2.0 license.
There are some open-source competitors to Android Studio for writing Android applications. For example, PhoneGap is an open-source program, based on Node.js, that allows developers to write cross-platform mobile applications in HTML, CSS, and JavaScript. Ruboto enables Android app development in Ruby. However, these projects remain suboptimal for a large number of use cases; graphic-intensive apps written in PhoneGap, for instance, can feel slow and less responsive to user interaction than Android Studio apps, as the overhead of translating from JavaScript to Android code leads to inefficiencies. However, it can be easier to write simpler applications in languages like JavaScript or Ruby than Android Studio's Java, which may make third-party choices more attractive to some developers than Google's official offering.
Nonetheless, with major overall improvements in its speed of developing,
building, and testing high-quality applications, Android Studio appears to
be the standard for high-quality Android app development for the
foreseeable future.
Index entries for this article | |
---|---|
GuestArticles | Saunders, Adam |