A4: Automatically Assisting Android API Migrations Using Code Examples

Maxime Lamothe, Weiyi Shang, Tse-Hsun ChenarXiv 2018

Abstract

Android APIs evolve at a breakneck pace, frequently leaving developers to decipher complex implementation changes with minimal guidance. This paper introduces A3, a framework that automatically mines code examples from repositories like GitHub and Google Samples to learn API migration patterns. By leveraging Abstract Syntax Tree (AST) matching and Data-Flow Graphs (DFG), A3 automates migrations or provides precise implementation guidance. Evaluation shows that A3 achieves high precision (96.7%) and reduces developer migration effort by nearly 30%, with professional developers seeing speedups of up to 46%.

Introduction

The Android ecosystem moves fast, with an average of 115 API updates per month. While official documentation usually specifies what has been deprecated (e.g., "use Method B instead of Method A"), it often fails to explain the how—the specific structural code changes, new parameters, or context required to make the switch. This gap leads to "migration lag," resulting in apps that are buggy, insecure, or unable to utilize new OS features.

Example of a code migration involving parameter changes.

Existing tools often require developers to manually demonstrate a migration first, which is counterproductive for those who do not know how to perform the migration in the first place. A3 addresses this by learning from the collective knowledge of the open-source community.

The A3 Framework

A3 is a two-step framework designed to bridge the documentation gap by mining and applying migration patterns.

1. Learning Patterns

A3 extracts a list of all public methods from Android documentation and searches through version control histories (like Git) of example projects. It uses lexical matching followed by Abstract Syntax Tree (AST) matching to identify exactly how an API call changed between two versions of a file.

2. Applying Migrations

To migrate a target app, A3 utilizes Data-Flow Graphs (DFG) to ensure the context of the example matches the context of the app. By comparing the "before" and "after" graphs of the example, it creates a mapping that transforms the app's code, handling variable renaming and parameter additions automatically. Crucially, A3 works with "partial" ASTs, allowing it to function even if the source code is missing dependencies or isn't fully compilable.

The A3 system architecture for identifying and applying migrations.

Key Insights and Results

The researchers evaluated A3 using Google Samples, FDroid apps, and a volunteer developer sample.

  • Complexity of Migrations: The study found that 56% of migrations were classified as "Hard," involving complex changes like adding contextual data or changing object types, rather than simple method renames.
  • Performance: A3 identified 80 migration patterns with 96.7% precision and 97% recall. In a test of 80 migration candidates across 32 apps, A3 provided successful assistance in 71 cases.
  • Developer Productivity: In a user study with 15 developers, those using A3 completed migrations 29% faster than those using traditional tools. Professional developers saw an even higher speedup of nearly 46%. Participants rated the usefulness of A3's suggestions at 4.3 out of 5.

Conclusion

A3 demonstrates the power of mining "the crowd" to solve the "how-to" problem in API migrations. By focusing on data-flow and AST matching, it provides a robust solution for developers struggling to keep up with the fast-paced Android ecosystem. Future work will focus on expanding the system to handle multi-file migrations and more complex control flows.

Summary updated

BibTeX
@misc{lamothe2018automatically,
  author = {Maxime Lamothe and Weiyi Shang and Tse-Hsun Chen},
  title = {{A4: Automatically Assisting Android API Migrations Using Code Examples}},
  year = {2018},
  eprint = {1812.04894},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1812.04894},
}
Figure