AndroEvolve: Automated Update for Android Deprecated-API Usages

Stefanus A. Haryono, Ferdian Thung, David Lo, Lingxiao Jiang, Julia Lawall, Hong Jin Kang, Lucas Serrano, Gilles MullerICSE (Companion Volume) 2020 · DOI

Abstract

The Android operating system (OS) is frequently updated, with each new version often involving API deprecation. Usages of deprecated APIs in Android apps must be updated to ensure compatibility with both old and new versions of the OS. In this work, we propose AndroEvolve, an automated tool to update usages of deprecated Android APIs that addresses the limitations of the state-of-the-art tool, CocciEvolve. AndroEvolve utilizes data flow analysis to solve the problem of out-of-method-boundary variables and variable denormalization to remove the temporary variables introduced by previous automation methods. We evaluated the accuracy of AndroEvolve using a dataset of 360 target files and 20 deprecated Android APIs, where AndroEvolve produced 319 correct updates, compared to CocciEvolve which produced 249. Evaluations also demonstrated that the code produced by AndroEvolve has significantly higher readability and naturalness.

Introduction

The Android ecosystem is characterized by rapid evolution. With each new iteration of the OS, Google frequently deprecates older APIs in favor of modern alternatives that offer improved performance, security, or functionality. This creates a significant maintenance burden for developers, leading to "Android fragmentation." To ensure applications remain compatible across a wide range of devices, developers must constantly migrate their codebases from deprecated APIs to their updated counterparts.

Manual migration is not only tedious but also prone to errors. While automated tools like AppEvolve and CocciEvolve have been developed to assist in this process, they face two primary challenges:

  1. Method Boundary Limitations: Existing tools often fail to resolve variable values defined outside the immediate scope of the method being updated.
  2. Code Quality Issues: Automated fixes often introduce "temporary variables" or "gibberish" naming conventions, resulting in code that is difficult for humans to read and maintain.

The AndroEvolve Framework

AndroEvolve addresses these challenges through a specialized two-phase workflow: Update-Script Creation and Update-Script Application.

Figure 1: The two-phase workflow of AndroEvolve, illustrating the creation and application of update scripts.

Data Flow Analysis (DFA)

To overcome method boundary issues, AndroEvolve employs a "bottom-up search" strategy using the JavaSymbolSolver. By recursively tracing variables back to their original definitions—even across different methods or complex object instantiations—the tool can accurately populate the arguments required by the new API. This deep context awareness ensures that the migration is logically sound and correctly handles variables that originate outside the immediate function call.

Variable Normalization and Denormalization

A core innovation of AndroEvolve is its approach to code readability. During the update process, the tool performs normalization to standardize variable names, allowing it to match patterns from a single "after-update" example. However, to prevent the "messy code" problem seen in previous tools, AndroEvolve includes a crucial denormalization step. This reverts temporary placeholders back to the original variable names used in the developer's codebase, ensuring the final patch integrates seamlessly and looks like human-written code.

Evaluation and Results

The effectiveness of AndroEvolve was evaluated using a dataset of 360 target files across 20 different deprecated Android APIs, sourced from public GitHub projects.

Accuracy

AndroEvolve demonstrated a significant performance leap over the previous state-of-the-art tool, CocciEvolve. It successfully produced 316 correct updates (a success rate of nearly 88%), representing a 26.9% improvement over CocciEvolve’s 249 correct updates.

Readability and Naturalness

Beyond functional correctness, the tool was evaluated for its impact on code quality:

  • Manual Evaluation: In assessments by experienced Android engineers, AndroEvolve’s output was rated 83% more readable than that of its predecessors.
  • Naturalness Score: On a 1-5 Likert scale (where 5 represents human-like code), AndroEvolve achieved a near-perfect score of 4.917, whereas CocciEvolve scored only 2.433.

Conclusion

AndroEvolve proves that automated API migration can be both accurate and readable. By treating code aesthetics as a functional requirement and utilizing global data flow analysis, the tool provides a practical solution for developers struggling with Android's fast-paced API lifecycle. While currently optimized for one-to-one API mappings, its ability to learn from a single example makes it a flexible and powerful addition to the Android developer's toolkit.

Summary updated

BibTeX
@inproceedings{haryono2020androevolve,
  author = {Stefanus A. Haryono and Ferdian Thung and David Lo and Lingxiao Jiang and Julia Lawall and Hong Jin Kang and Lucas Serrano and Gilles Muller},
  title = {{AndroEvolve: Automated Update for Android Deprecated-API Usages}},
  booktitle = {ICSE (Companion Volume)},
  year = {2020},
  doi = {10.1109/icse-companion52605.2021.00021},
}
Figure