Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical Android development techniques?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the practical Android development techniques". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the practical Android development techniques?"

1. Kotlin

Kotlin is often seen as the next Java, sponsored by Google and JetBrains (Android Studio developer). Java has been the preferred development language for Android applications from the very beginning, but Kotlin has become popular rapidly in recent years, and now nearly 60% of the 10000 Google Play applications use Kotlin [3]. Although you will continue to use Kotlin in a few cases where you need to access the underlying native code, in other cases, Kotlin can be a substitute for Java.

The main advantage of Kotlin is full interoperability with Java, which means that developers can migrate old code as much as possible without having to completely rewrite the entire application. The two languages are so compatible that Android Studio can even automatically convert from Java to Kotlin.

This compatibility, coupled with cleaner syntax and hundreds of minor improvements, makes Kotlin the fourth most "most popular" and fifth most "wanted" programming language in StackOverflow's 2019 developer survey [4], and the highest of all mobile programming languages.

A good way to migrate an existing application is to convert an existing Java file to Kotlin when you modify it. Although this means that you have to convert frequently edited files, which will increase the complexity of code review (such as facing potential conflicts), because the converted area can be reviewed, you can ensure that any problems can be found.

Currently 86% of the Kotlin code used in Candyspace (and growing), the remaining 14% is utility / conversion code, which has not been changed for some years.

2. Jetpack

Google's AndroidX/Jetpack library is a set of utilities designed to simplify common application requirements. For example, Room [5] for a database on a device, or LiveData [6] for updating the display when the underlying data changes.

With the Jetpack library, the new project saves the hassle of reinventing the wheel and does not have to wait for other developers to open up their implementation, and every developer now has access to those basics. These libraries are updated frequently, new features are constantly introduced, and bug fixes are released in a timely manner. Because these libraries are built to work together, more use of AndroidX libraries helps minimize accidents in applications.

Using Jetpack libraries from the start of development work can save hundreds of hours, but we can also migrate existing applications to Jetpack libraries. Although it may seem troublesome, because these libraries are very popular, guidelines for migration efforts are also easy to find. At the very least, the underlying Android elements (views, fragments, and so on) can be automatically converted [7].

At Candyspace, we used Data Binding and ViewModel, and may soon add Room and Navigation.

3. Modular design

For a long time, the application has been built into a huge "application" module, which contains everything the whole application needs. While this does make it easier to share resources, it also means that some parts of the application cannot be reused by other applications / open source projects; more importantly, the entire code base must be recompiled when changes are made to the application.

In contrast, if the application consists of many smaller modules, you only need to recompile the code that made the changes, greatly reducing the build time. In addition, modular design opens the door for advanced Android features, such as real-time applications-users can use some of the functions of your application without installing any content, and dynamic features-install various parts of the application on demand.

Splitting an existing application into multiple modules can be a complex task, as it will uncover previously hidden problems ("what is DateUtility? why does every class need it!?" But once the transformation is complete, the code base will enter a healthier state In addition, if a new application requires similar functionality, existing modules can be quickly reused, saving a lot of time!

While designing a modular architecture can be a complex task, I have written some guiding principles [8] that were inspired by Nikits Kozlov's article on modularity and build time [9]. Plaid also wrote an article about their experience in migrating to modular design [10].

At Candyspace, our application designs are fully modular to minimize the disruption of build time to development work.

4. App Bundle

When using traditional APK to distribute applications to users' devices, all resources prepared for all devices must be installed. This means that there may be five copies of each bitmap image (for different screen precision), multiple library versions for different device architectures, and even multiple sets of margins and padding values.

When you use App Bundle to distribute an application, users download APK that contains only the resources they actually need. As a result, the average application size will be reduced by 20%, and the application size will be reduced more significantly after the unoptimized application changes the format.

An example of reducing the size of an application (data from Google Imax O 2018)

App Bundles was born 18 months ago, but more than 25% of applications have been installed using this format! This is the format recommended by Google [11], and most apps can use it with little change, simply by processing App Bundle's signature on the Play store.

At Candyspace, we are migrating to App Bundles while trying to avoid disrupting our existing workflows (Slack, QAing builds, non-Google Play installations). Alistair Sykes's article is a great migration reference [12], taking into account CI servers, Slack, and Google Play internal application sharing.

5. test

Yes, the test. Of course, testing is not a shiny new feature, nor is it content that users can see, but to ensure the reliability of an application that already has a user base, you have to test your application thoroughly. Because the collapse rate will directly affect your Play store score (and it will definitely drag it down! So you should try to keep it at a low level

The three most common test types of Android are (in descending order):

Unit tests, such as: will my square root function return the square root?

These tests will make up most of your testing process, and they will be used to ensure that specific code snippets (such as a function) work as expected. When you build confidence in a part, you can use it for …

Integration testing. For example: can my math module work with the location module?

These tests ensure that your code areas (modules or layers) work together properly. Once you know that the components of the application can communicate with each other correctly, you can add.

Automated UI testing, for example: can the user mark a location on the application?

Only these tests are run on the device or emulator, which ensures that the application provides a complete user experience as expected. These tests are usually much slower (and more inconvenient to run) than other types of tests.

Google recommends that the distribution of tests be 70% of unit tests, 20% of integration tests, and 10% of large tests, with a smaller portion requiring longer execution time, maintenance time, and implementation time.

The best test resource is the official document [13], because it provides an introduction to all test types and tutorials on how to implement them into the project.

At Candyspace, we focus on unit testing, which accounts for a larger percentage than Google suggests, to ensure that the behavior of all new classes is predictable. We are also currently improving automated UI testing to reduce reliance on manual testing.

In any area of programming, there are a hundred different opinions about the best way to solve a problem; but Android has an absolute advantage: Android has a large developer community, which means that a very good new technology will quickly spread among developers. When you ask strangers for help on the Internet, if you are looking for "Jetpack LiveData" instead of "libraries copied and converted by previous developers from Web developer friends", you are much more likely to get the answer!

At this point, I believe you have a deeper understanding of "what are the practical Android development technologies?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report