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

How to use the new function of Android Studio3.0

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to use the new features of Android Studio3.0". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Brief introduction:

Android Studio is the official IDE of Android. It is built for Android to speed up your development and help you build optimal applications for each Android device.

It provides tools tailored for Android developers, including a wealth of code editing, debugging, testing and performance analysis tools.

Last Thursday, Google finally released Android Studio 3.0 after more than half a year of hard work, giving Android developers a satisfactory answer. As usual, every time a new version of the development tool is released, many cautious friends still worry about stability, whether there are holes and other problems, choose to wait on the sidelines and wait for a period of time to update and upgrade.

After looking at the introduction of the new features of the new development tools on the official website, I chose to upgrade that day. As a matter of fact, I did struggle for a long time, but so far, no so-called pit has been found. We just need to make some configuration adjustments to the old project. The overall response speed and the use of new features are still worth upgrading. This article introduces the practical changes brought to us by the new version of the development tools, and tells you with practical experience how to modify the configuration of the old project.

Changes brought about by 3.0

Kotlin Support

Prior to Android Studio 3.0, using the Kotlin language to develop Android applications required additional configuration of Kotlin plug-ins. The new version has built-in support for Kotlin by default to reduce our work on configuration.

Select toolbar Code-> Convert Java File To Kotlin File, or use shortcut keys to convert Java files to Kotlin files with one click.

Note: with regard to the use of keyboard shortcuts, you can use Command + Shift + A to open the Find Action window and enter keywords to find the corresponding functions and shortcuts, as shown in the Gif diagram above.

Java 8 Support

The default support for Java 8 language features eliminates the need to add jackOptions to the build.gradle configuration file. If you use it, remember to delete:

Android {... DefaultConfig {... / / Remove this block. JackOptions {enabled true...}

Select the toolbar File-"Project Structure, and change the Source Compatibility and Target Compatibility options to 1.8 to make our project support Java 8 language features.

Android Profiler

The Android Monitor tool we used in the past has been replaced by Android Profiler since version 3.0. As shown in the figure, there is an extra Android Profiler button in the column of run button:

Android Profiler provides three sharp tools for debugging and analysis: CPU, Memory and Network. Tracking the running status of Apk in real time can help us to do some performance tuning visually.

These three tools are very useful in the development stage, such as CPU Profiler can analyze thread usage in applications, Memory Profiler can detect memory leaks, Network Profiler can intercept network requests to achieve packet capture function and so on. Here are some pictures to briefly preview the elegant demeanor of these three tools:

For more details on the use of these tools, please refer to the official introduction:

CPU Profiler guide

Memory Profiler guide

Network Profiler guide

Device File Explorer

This function is amazing. The resource manager brought by the new version of the development tool allows us to access the file system connected to the device, enabling convenient file transfer from PC to mobile phone or simulator. With this tool, you can bid farewell to the previously used "File transfer Assistant" and other third-party tools.

Adaptive Icons wizard

Select File-> New-> Image Asset, using the tools provided by Android Studio to create image resources has always been one of the development tools. The tool now supports vector drawables format and can create desktop icons that can be adapted to various shapes on Android 8.0 systems.

URL intent-filter validator

This function is also quite sweet. The Manifest manifest file begins to support a special tag that tests whether a given Url string conforms to the rules defined by the intent-filter tag content. For example:

As shown in the figure, the data tag is used to define a Url rule, and the tools:validation tag is used to verify an incorrect test Url address. The detector can automatically identify and give an error prompt. This example is very simple, you can see the mistake with the naked eye. Well, if it is a more complex rule, it may not be so easy to see. At this time, this tool can come in handy.

APK Analyzer

Version 3. 0 further enhances the functionality of APK Analyzer. The main points are: for APK files that have been confused with ProGuard, we can upload mapping.txt files for code restoration; Dex files provide the size of each package directory; and so on.

Other featur

In addition to the changes described above, there are other changes, large and small. For example, Layout Inspector and Layout Editor tools have been adjusted on UI, such as the enhanced use of App Links Assistant and Firebase App Indexing Assistant, which are left for everyone to explore and discover. You can also visit the Android Studio Release Notes website to learn more about the release details of version 3.0.

The adaptation of old projects

The release of Android Studio 3.0 coincided with the release of Android Plugin for Gradle 3.0.0. The overall compilation speed has been greatly improved. After upgrading Android Studio, the old project needs to make some changes before it can be compiled by Gradle. Here is an introduction to what needs to be changed according to one of my actual projects. Of course, maybe your project doesn't need these, or it may be more than that.

DistributionUrl

Plugin 3.0.0 + the minimum version of Gradle that needs to be configured is 4.1. We can set the version of Android Plugin by File-> Project Structure-> Project, or modify the content of the gradle.properties file and add the distributionUrl attribute:

DistributionUrl=https\: / / services.gradle.org/distributions/gradle-4.1-all.zip

Google's Maven repository

The new version of the Android Studio tool defaults to Google's Maven Repository for downloading dependent Android Support Library, replacing Android SDK Manager's local dependency. Therefore, you need to add a line of google () to the build.gradle file under the root of the project:

Allprojects {repositories {google ()}}

BuildToolsVersion

Android Plugin For Gradle 3.0.0 defaults to the minimum version of the compilation tool needed to automatically add plug-ins. Therefore, we no longer need to manually add a line of code for the buildToolsVersion attribute to build.gradle. For older projects, you can remove this line of configuration, such as:

Android {compileSdkVersion 26 / / remote buildToolsVersion buildToolsVersion "25.0.2"...}

Flavor dimensions

Starting with Plugin 3.0.0, if build.gradle has a custom productFlavors configuration, you need to add a definition flavorDimensions (flavor dimension). Otherwise, the compilation reports an error:

Rror:All flavors must now belong to a named flavor dimension.The flavor 'flavor_name' is not assigned to a flavor dimension.

The advent of flavorDimensions makes the types of building variants more diverse:

Number of varieties that can be constructed = number of flavor dimensions * number of construction types

Detailed use of the configuration can be referenced to build variants. For old projects, if it is simple, you can define a flavor dimension at will to ensure that the compilation is passed, such as ("minApi" here can be freely defined):

FlavorDimensions "minApi" productFlavors {beta {dimension "minApi"...} production {dimension "minApi"...}}

Each () and outputFile ()

Version 3.0.0 of Plugin removes some API for compiling configurations, the more common of which are each () and outputFile (), two of which are often used to modify output

The method of the Apk file name and path.

As mentioned in the previous article summarizing the common implementation of Android Gradle scenarios, custom output APK filenames can do this:

Android {android.applicationVariants.all {variant-> variant.outputs.each {output-> output.outputFile = new File (output.outputFile.parent, rootProject.getName () + "-" + buildType.name + "-" + releaseTime () + "- v" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk");}

However, a compilation error occurs when using Plugin 3.0.0. We need to modify the each () and outputFile () methods to all () and outputFileName, for example:

Android {android.applicationVariants.all {variant-> variant.outputs.all {outputFileName = rootProject.getName () + "-" + buildType.name + "-" + releaseTime () + "- v" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk";}} "how to use the new features of Android Studio3.0" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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