Towards High-Quality Android Applications Development with Kotlin Bruno Gois Mateus
Total Page:16
File Type:pdf, Size:1020Kb
Towards high-quality Android applications development with Kotlin Bruno Gois Mateus To cite this version: Bruno Gois Mateus. Towards high-quality Android applications development with Kotlin. Mobile Computing. Université Polytechnique Hauts-de-France, 2021. English. NNT : 2021UPHF0012. tel- 03247062 HAL Id: tel-03247062 https://tel.archives-ouvertes.fr/tel-03247062 Submitted on 2 Jun 2021 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. PhD Thesis Université Polytechnique Hauts-de-France and from INSA Hauts-de-France Subject: Computer Science Presented and defended by Bruno GÓIS MATEUS On March 26, 2021, Valenciennes Doctoral School: Sciences Pour l’Ingénieur (ED SPI 072) Research team, Laboratory: Département d’Informatique Laboratory of Industrial and Human Automation control, Mechanical engineering and Computer Science (LAMIH UMR CNRS 8201) Towards high-quality Android applications development with Kotlin JURY Committee President - Káthia MARÇAL DE OLIVEIRA. Professor at Université Polytechnique Hauts-de-France. Reviewers - Guilherme HORTA TRAVASSOS. Professor at Federal University of Rio de Janeiro. - Jacques KLEIN. Professor at University of Luxembourg. Examiner - Dalila TAMZALIT. Associate Professor at Université de Nantes. Supervisor - Christophe KOLSKI. Professor at Université Polytechnique Hauts-de-France. Co-Supervisor - Matias MARTINEZ. Associate Professor at Université Polytechnique Hauts-de-France. Colophon Doctoral dissertation entitled “Towards high-quality Android applications development with Kotlin”, written by Bruno GÓIS MATEUS, completed on May 4, 2021, typeset with the document preparation system LATEX and the yathesis class dedicated to theses prepared in France. Thèse de doctorat Université Polytechnique Hauts-de-France et l’ INSA Hauts-de-France Discipline : Informatique Présentée et soutenue par Bruno GÓIS MATEUS Le 26 mars 2021, à Valenciennes École doctorale : Sciences Pour l’Ingénieur (ED SPI 072) Equipe de recherche, Laboratoire : Département d’Informatique Laboratory of Industrial and Human Automation control, Mechanical engineering and Computer Science (LAMIH UMR CNRS 8201) Vers un développement d’applications Android de haute qualité avec Kotlin JURY Présidente du jury - Káthia MARÇAL DE OLIVEIRA. Professeure à l’Université Polytechnique Hauts-de-France. Rapporteurs - Guilherme HORTA TRAVASSOS. Professeur au Federal University of Rio de Janeiro. - Jacques KLEIN. Professeur à l’University of Luxembourg. Examinatrice - Dalila TAMZALIT. Maître de conférences hdr à l’Université de Nantes. Directeur de thèse - Christophe KOLSKI. Professeur à l’Université Polytechnique Hauts-de-France. Co-encadrant - Matias MARTINEZ. mcf à l’Université Polytechnique Hauts-de-France. The Université Polytechnique Hauts-de-France and the INSA Hauts-de-France neither en- dorse nor censure authors’ opinions expressed in the theses: these opinions must be considered to be those of their authors. Keywords: Android development, Kotlin, adoption, evolution, migration, machine learning Mots clés : développement Android, Kotlin, adoption, évolution, migration, apprentissage automatique This thesis has been prepared at Département d’Informatique Laboratory of Industrial and Human Automation control, Mechanical engineering and Computer Science (LAMIH UMR CNRS 8201) Université Polytechnique Hauts-de-France Le Mont Houy F-59313 Valenciennes Cedex 9 The roots of education are bitter, but the fruit is sweet. Aristotle xiii Abstract In recent years, with more than 3 million applications on its official store, Google’s Android has dominated the market of mobile operating systems worldwide. Despite this success, Google has continued evolving its operating system and its toolkits to ease application development. In 2017 Google declared Kotlin as an official Android programming language. More recently, during the Google I/O 2019, Google announced that Android became ‘Kotlin-first’, which means that new API, libraries, and documentation will target Kotlin and eventually Java and Kotlin as preferred language to create new Android applications. Kotlin is a programming language that runs on the Java Virtual Machine (JVM) and it is fully interoperable with Java because both languages are compiled to JVM bytecode. Due to this characteristic, Android developers do not need to migrate their existing applications to Kotlin to start using Kotlin in these applications. Moreover, Kotlin provides a different approach to write applications because it combines object-oriented and functional features. Therefore, we hypothesize that the adoption of Kotlin by developers may affect different aspects of Android applications’ development. However, one year after this first announcement, there were no studies in the literature about Kotlin. In this thesis, we conducted a series of empirical studies to address these lacks and build a better understanding of creating high-quality Android applications using Kotlin. First, we carried a study to measure the degree of adoption of Kotlin. Our results showed that 11% of the studied Android applications had adopted Kotlin. Then, we analyzed how the adoption of Kotlin impacted the quality of Android applications in terms of code smells. We found that the introduction of Kotlin in Android applications initially written in Java produces a rise in the quality scores from 50% to 80% according to the code smell considered. We analyzed the evolution of usage of features introduced by Kotlin, such as Smart cast, and how the amount of Kotlin code changes over applications’ evolution. We found that the number of instances of features tends to grow throughout applications’ evolution. Finally, we focused on the migration of Android applications from Java to Kotlin. We found that 25% of the open source applications that were initially written in Java have entirely migrated to Kotlin, and for 19%, the migration was done gradually, throughout several versions, thanks to the interoperability between Java and Kotlin. This migration activity is challenging because: a) each migrated piece of code must be exhaustively tested after the migration to ensure it preserves the expected behavior; b) a project can be large, composed of several candidate files to be migrated. In this thesis, we present an approach to support migration, which suggests, given a version of an application written in Java and eventually, in Kotlin, the most convenient files to migrate. We evaluated our approach’s feasibility by applying two different machine learning techniques: classification and learning-to-rank. Our results showed that both techniques modestly outperform random approaches. Nevertheless, our approach is the first that proposes the use of machine learning to recommend file-level migrations. Therefore, our results define a baseline for future work. Since the migration from Java to Kotlin may positively impact the application’s maintenance and that migration is time-consuming and challenging, developers may use our approach to select the files to be migrated first. Finally, we discuss several research perspectives opened by our results that can improve the experience of creating high-quality Android applications using Kotlin. Keywords: Android development, Kotlin, adoption, evolution, migration, machine learning xiv Résumé Ces dernières années, avec plus de 3 millions d’applications sur sa boutique officielle, Android de Google a dominé le marché des systèmes d’exploitation mobiles dans le monde entier. Malgré ce succès, Google a continué à faire évoluer son système d’exploitation et ses kits d’outils pour faciliter le développement des applications. En 2017, Google a déclaré Kotlin en tant que langage de programmation Android officiel. Plus récemment, pendant le Google I/O 2019, Google a annoncé qu’Android devenait ‘Kotlin-first’, ce qui signifie que de nouvelles API, bibliothèques et documentations cibleront en priorité Kotlin, et éventuellement Java et Kotlin, comme langage préféré pour créer de nouvelles applications Android. Kotlin est un langage de programmation qui s’exécute sur la machine virtuelle Java (JVM) et il est entiè- rement interopérable avec Java car les deux langages sont compilés en bytecode JVM. En raison de cette caractéristique, les développeurs Android n’ont pas besoin de migrer leurs applications existantes vers Kotlin pour commencer à utiliser Kotlin dans ces applications. De plus, Kotlin propose une approche différente pour écrire des applications car il combine des fonctionnalités orientées objet et fonctionnelles. Par conséquent, nous émettons l’hypothèse que l’adoption de Kotlin par les développeurs Android peut affecter différents aspects du développement des applications Android. Cependant, un an après cette première annonce, il n’y avait aucune étude dans la littérature sur Kotlin. Dans cette thèse, nous avons mené une série d’études empiriques pour combler ces lacunes et développer une meilleure compréhension de la création d’applications Android de haute qualité à l’aide de Kotlin. Tout d’abord, nous avons réalisé une étude pour mesurer le degré d’adoption