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 optimize the Apk of Android development optimization

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

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "Android development optimization of Apk how to optimize", detailed content, clear steps, details handled properly, I hope that this "Android development optimization of Apk how to optimize" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

Understand the structure of APK

Before discussing how to reduce the size of an application, you need to understand the structure of the application APK. The APK file consists of a Zip compressed file that contains all the files that make up the application. These include Java class files, resource files, and files for compiled resources.

APK contains the following directories:

META-INF/: contains CERT.SF and CERT.RSA signature files, as well as MANIFEST.MF manifest files.

Assets/: contains the resources of the application; the application can retrieve these resources using the AssetManager object.

Res/: contains resources (pictures, audio and video, etc.) that are not compiled into resources.arsc.

Lib/: contains compiled code specific to the processor software layer. This directory contains subdirectories for each platform type, such as armeabi, armeabi-v7a, arm64-v8a, x86, x86, and mips.

APK also contains the following files. Of these files, only AndroidManifest.xml is required.

Resources.arsc: contains compiled resources. This file contains the XML content in all configurations of the res/values/ folder. The packaging tool extracts the XML content, compiles it into a binary file, and compresses the content. This content includes language strings and styles, as well as paths to content, such as layout files and pictures, that are not directly included in the resources.arsc file.

Classes.dex: contains classes compiled in a DEX file format that the Dalvik/ART virtual machine can understand.

AndroidManifest.xml: contains the core Android manifest file. This file lists the name, version, access rights, and referenced library files of the application. This file uses Android's binary XML file

Android Size Analyzer

The Android Size Analyzer tool makes it easy to discover and implement a variety of strategies to reduce application size.

First download and install the Android Size Analyzer plug-in in the plug-in market in Android Studio. After installing the plug-in, select Analyze > Analyze App Size from the menu bar to run the application size analysis on the current project. After analyzing the project, the system displays a tool window with suggestions on how to reduce the size of the application.

Remove unused resources

The key to APK slimming is in one word: delete! Delete it if it's useless.

Enable resource reduction (no packaging)

If resource reduction: shrinkResources is enabled in the applied build.gradle file, Gradle can automatically ignore unused resources when packaging APK. Resource reduction works only when used with code reduction: minifyEnabled. After the code reducer removes all unused code, the resource reducer can determine which resources the application still uses.

Android {/ / Other settings buildTypes {release {minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile ('proguard-android.txt'),' proguard-rules.pro'} dynamic library packaging configuration

The so file is a dynamic library compiled by ndk and written by cUnix cymbal +, so it is not cross-platform. ABI is the abbreviation of Application binary Interface (Application Binary Interface), which defines how binaries (especially .so files) run on the corresponding system platform, from the instruction set used, memory alignment to available system function libraries. In the Android system, each CPU architecture corresponds to an ABI. Currently supported are: armeabi-v7a,arm64- v8aMagnex86Magnex86Zhi64. At present, most mobile devices on the market are based on arm architecture, and armeabi-v7a is compatible with almost all devices. So you can configure:

Android {defaultConfig {ndk {abiFilters "armeabi-v7a"}

For third-party services, such as Baidu Maps, Bugly, etc., will provide a full-platform cpu architecture. After the above configuration, it indicates that only armeabi-v7a will be packaged into Apk. Thereby reducing the APK size.

Read here, this "Android development optimization of Apk how to optimize" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related articles, welcome to follow the industry information channel.

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