AndroEvolve: automated Android API update with data flow analysis and variable denormalization

Stefanus A. Haryono, Ferdian Thung, David Lo, Lingxiao Jiang, Julia Lawall, Hong Jin Kang, Lucas Serrano, Gilles MullerEmpir. Softw. Eng 2020 · OpenReview

Abstract

The Android operating system is frequently updated, with each version bringing a new set of APIs. New versions may involve API deprecation; Android apps using deprecated APIs need to be updated to ensure the apps' compatibility with old and new versions of Android. Updating deprecated APIs is a time-consuming endeavor. Hence, automating the updates of Android APIs can be beneficial for developers. CocciEvolve is the state-of-the-art approach for this automation. However, it has several limitations, including its inability to resolve out-of-method-boundary variables and the low code readability of its update due to the addition of temporary variables. In an attempt to further improve the performance of automated Android API update, we propose an approach named AndroEvolve, which addresses the limitations of CocciEvolve through the addition of data flow analysis and variable name denormalization. Data flow analysis enables AndroEvolve to resolve the value of any variable within the file scope. Variable name denormalization replaces temporary variables that may present in the CocciEvolve update with appropriate values in the target file. We have evaluated the performance of AndroEvolve and the readability of its updates on 360 target files. AndroEvolve produces 26.90% more instances of correct updates compared to CocciEvolve. Moreover, our manual and automated evaluation shows that AndroEvolve updates are more readable than CocciEvolve updates.

Introduction

The Android ecosystem is characterized by rapid evolution. With every new version, Google introduces new APIs and deprecates older ones. This creates a persistent challenge known as "Android fragmentation," where developers must continuously update their codebases to leverage new features while maintaining backward compatibility for older devices.

Manual updates are labor-intensive and error-prone. While previous tools like AppEvolve and CocciEvolve attempted to automate these updates, they faced two significant hurdles:

  1. Scope Blindness: These tools often failed when an API argument was defined outside the immediate method scope (e.g., as a class-level field).
  2. Reduced Readability: To simplify code transformations, these tools often introduced "robot code"—messy temporary variables (e.g., parameterVariable0) that made the resulting code difficult for humans to read and maintain.

AndroEvolve is designed to overcome these limitations by combining data flow analysis (DFA) with a novel "variable denormalization" step.

Methodology

AndroEvolve enhances the existing CocciEvolve framework by introducing a more sophisticated understanding of code context and a focus on human-readable output. The overall workflow is divided into two main phases: Update Script Creation and Update Script Application.

The AndroEvolve workflow, illustrating the two-stage process of script creation and application.

Data Flow Analysis (DFA)

Using a custom lightweight engine built on Javaparser, AndroEvolve performs a bottom-up search to resolve variable values. Unlike previous tools that were limited to intra-procedural analysis, AndroEvolve's DFA can resolve variables within the entire file scope. If an API requires an object defined elsewhere in the file, the DFA identifies that definition and integrates it into the update script. It can even copy necessary method or class definitions to ensure the updated code remains functional.

Variable Denormalization

A common technique in automated refactoring is "normalization," which simplifies complex expressions into temporary variables to facilitate pattern matching. However, this often leaves the final code cluttered with non-descriptive variable names. AndroEvolve introduces a post-processing step to reverse this effect.

Detailed steps of the variable denormalization process.

As shown in the figure above, the tool locates API invocations and temporary variable definitions, replaces the temporary variables with the original meaningful expressions, and then removes the redundant temporary definitions. This ensures the final code appears natural and hand-written.

Evaluation and Results

The researchers evaluated AndroEvolve using a dataset of 360 target files sourced from real-world GitHub projects. These files covered 20 different deprecated Android APIs. The performance was benchmarked directly against CocciEvolve.

  • Accuracy: AndroEvolve successfully updated 316 out of 360 files, achieving an accuracy of 87.8%. This represents a 26.9% improvement over CocciEvolve, which managed only 249 successful updates.
  • Readability:
    • Automated Metrics: Using standard readability scoring, AndroEvolve's output scored approximately 50% higher than the baseline.
  • Human Evaluation: In a blind study with experienced Android engineers, AndroEvolve’s updates were rated 83% more readable and "natural" than CocciEvolve's.
  • Efficiency: The tool is highly efficient, with an average processing time of less than 15 seconds per file.

Discussion

The success of AndroEvolve highlights two critical insights for automated software engineering:

  • Context is Essential: The significant jump in accuracy demonstrates that automated refactoring must look beyond individual functions. Understanding the "life" of a variable across a file is necessary for correct API migration.
  • Readability is a Functional Requirement: If automated tools produce unreadable code, they increase the long-term maintenance burden. By treating denormalization as a core pipeline component, AndroEvolve bridges the gap between machine logic and human-centric development.

Conclusion and Future Work

While AndroEvolve represents a significant step forward, it currently operates within a "file scope" boundary. It cannot resolve variables defined in different files within the same project. Future work will focus on expanding the data flow analysis to a full project scope and improving the engine's ability to handle complex "one-to-many" API mappings. Additionally, the authors aim to address current limitations regarding inner class constructors and more intricate code structures.

Summary updated

Abstract

The Android operating system is frequently updated, with each version bringing a new set of APIs. New versions may involve API deprecation; Android apps using deprecated APIs need to be updated to ensure the apps’ compatibility with old and new Android versions. Updating deprecated APIs is a time-consuming endeavor. Hence, automating the updates of Android APIs can be beneficial for developers. CocciEvolve is the state-of-the-art approach for this automation. However, it has several limitations, including its inability to resolve out-of-method variables and the low code readability of its updates due to the addition of temporary variables. In an attempt to further improve the performance of automated Android API update, we propose an approach named AndroEvolve, that addresses the limitations of CocciEvolve through the addition of data flow analysis and variable name denormalization. Data flow analysis enables AndroEvolve to resolve the value of any variable within the file scope. Variable name denormalization replaces temporary variables that may present in the CocciEvolve update with appropriate values in the target file. We have evaluated the performance of AndroEvolve and the readability of its updates on 372 target files containing 565 deprecated API usages. Each target file represents a file from an Android application that uses a deprecated API in its code. AndroEvolve successfully updates 481 out of 565 deprecated API invocations correctly, achieving an accuracy of 85.1%. Compared to CocciEvolve, AndroEvolve produces 32.9% more instances of correct updates. Moreover, our manual and automated evaluation shows that AndroEvolve updates are more readable than CocciEvolve updates.
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 Android API update with data flow analysis and variable denormalization}},
  booktitle = {Empir. Softw. Eng},
  year = {2020},
  url = {https://openreview.net/forum?id=tVHG5tUtBg},
}
Figure