EcoAndroid: An Android Studio Plugin for Developing Energy-Efficient Java Mobile Applications Ana Ribeiro ∗ and Jo˜ ao F. Ferreira † INESC-ID & Instituto Superior T´ ecnico University of Lisbon, Lisbon, Portugal Email: ∗ anasofiaribeiro@tecnico.ulisboa.pt, † joao@joaoff.com Alexandra Mendes University of Beira Interior, Covilh˜ a, Portugal HASLab, INESC TEC, Porto, Portugal Email: alexandra@archimendes.com Abstract—Mobile devices have become indispensable in our daily life and reducing the energy consumed by them has become essential. However, developing energy-efficient mobile applications is not a trivial task. To address this problem, we present EcoAndroid, an Android Studio plugin that automatically applies energy patterns to Java source code. It currently supports ten different cases of energy-related refactorings, divided over five energy patterns taken from the literature. We used EcoAndroid to analyze 100 Java mobile applications (≈ 1.5M LOC) and we found that 35 of the projects had a total of 95 energy code smells. EcoAndroid was able to automatically refactor all the code smells identified. Index Terms—Green Software, Energy Consumption, Energy Patterns, Code Smells, Android, Refactoring I. I NTRODUCTION Mobile devices have become a fundamental accessory in current day-to-day life. They are used as credit cards, work tools, educational helpers, among many other useful purposes. Unfortunately, the battery power on them is finite and, despite the advances in hardware and battery technology, the needs of most users are not yet met. Indeed, Wilke et al. [1] analyzed comments left in the Google Play market place for Android applications and concluded that 18% of the complaints were related to energy problems. The reduction of the energy consumed by mobile devices has thus become an important non-functional requirement [2], [3]. One way of decreasing the energy consumed by a mobile device is to ensure that the mobile applications that the device runs are energy-efficient. However, this is a complex task since a lot of factors can influence energy consumption, such as: the mobile networking technology used (3G, GSM or WiFi) [4]; heavy graphic processing; and screen usage while on an application. Taking these factors into consideration is not always trivial, as they can be easily overlooked by developers when coding. An approach that makes the development of energy-efficient mobile applications easier is following so-called energy pat- terns, which are code patterns known to use energy prudently. Work documenting these patterns has been growing in recent years [5]–[8]. An extremely useful resource is Cruz and Abreu’s catalog of energy-related patterns [5]. This catalog can be of great assistance to mobile application developers, as it describes each pattern and its context, also providing a series of examples and references. However, the manual application of these patterns is far from trivial and can be time-consuming. To address this problem, we present EcoAndroid, an An- droid Studio plugin that automatically applies a set of energy patterns to Java source code. At the time of writing, the plugin supports ten different cases of energy-related refactorings, dis- tributed over five energy patterns taken from the literature [5]. We used EcoAndroid to analyze 100 Java projects (≈ 1.5M LOC) from F-Droid, a Free and Open Source Android App Repository, and we found that 35 of the projects had a total of 95 energy code smells detected by the plugin. EcoAndroid was able to automatically refactor all the code smells identified. EcoAndroid is an extendable Android Studio plugin, created to assist developers in creating energy-efficient mobile appli- cations. Since it is open source 1 , it can also be extended by the research community to explore new techniques that help in the creation of more energy-efficient mobile applications. EcoAndroid is currently available in the JetBrains Market- place: https://plugins.jetbrains.com/plugin/15637-ecoandroid Illustrative Example: To illustrate the type of refactoring that EcoAndroid is capable of, we show in Figure 1 an example of a refactoring suggested and applied by EcoAndroid. It consists in the application of the Cache - Check Metadata energy pattern in the Android mobile application Taskbar 2 , which puts a start menu and recent apps tray on top of the screen that is accessible at any time. Taskbar is a popular application: at the time of writing, its GitHub project has 405 stars and it has been downloaded more than 1 million times from the app store Google Play. Figure 1a shows the original source code, where the code smell was detected. There is an opportunity to optimize the energy efficiency of the code by caching the object bundle and only executing the code if the object has changed. Figure 1b shows the source code after the refactoring automatically performed by EcoAndroid. 1 EcoAndroid Github Repository: https://github.com/sr-lab/EcoAndroid 2 Taskbar (Google Play): https://play.google.com/store/apps/details?id=com. farmerbb.taskbar.