Table of Contents 1, Preface 2, aaptOptions structure brief analysis 3, aaptOptions attributes 4, write in the last

One, foreword

Share aaptOptions configuration today. Aapt is the Android Asset Packaging Tool. This allows you to configure the details of packaging.

Ii. Structure analysis of aaptOptions

1. Form of existence

Will map to com. Android. Build. Gradle. Internal. DSL. AaptOptions class. This class is relatively simple and does not inherit from any classes

2. Location

android{ aaptOptions{ ... }}Copy the code

3. AaptOptions attributes

1, additionalParameters

  • Type: List< String >
  • Description: Add additional parameters to aAPT execution, add parameters can passaapt --helpTake a look.
  • Use:

For example, make a change package name

aaptOptions{
	// Change the package name to com.zinc.test
	additionalParameters '--rename-manifest-package'.'com.zinc.test'
}
Copy the code

AndroidManifest.xmlThe file is as follows, and the package name iscom.zinc.gradlestudy Running at terminal./gradlew clean aRThe compiled package is as follows, and the package name is changed tocom.zinc.test

2、 cruncherProcesses

  • Types: int
  • Description: Sets the number of threads to be processed.
  • Use:
aaptOptions{
	cruncherProcesses 4
}
Copy the code

3, failOnMissingConfigEntry

  • Types: Boolean
  • Description: Sets whether the configuration entry cannot be found and forces AAPT to return an error.
  • Use:
aaptOptions{
	failOnMissingConfigEntry true
}
Copy the code

4, ignoreAssets

  • Types: Boolean
  • Description: Set the resource to be ignored
  • Use:
aaptOptions{
	// If you omit images with the PNG suffix, only assets under assets are excluded
	ignoreAssets "*.png"
}
Copy the code

After using the above configuration, use the

./gradlew app:clean app:aR
Copy the code

The contents of the package are as follows,t121212.pngImages ending in ‘PNG’ are filtered out

5, ignoreAssetsPattern

  • Types: Boolean
  • Description: Set the resource to be ignored
  • Use:
aaptOptions{
	// If you omit images with the PNG suffix, only assets under res are excluded
	ignoreAssetsPattern '*.png'
}
Copy the code

IgnoreAssets and ignoreAssetsPattern are the same from a source point of view, The setIgnoreAssets method ends up calling setIgnoreAssetsPattern, as shown in the figure below. Both getIgnoreAssets and getIgnoreAssetsPattern return fields of ignoreAssetsPattern.

6, noCompress

  • Type: Collection< String >
  • Description: Whether to compress resources. “JPG” and “PNG” are not compressed by default. If ” is passed, it indicates that all resources are not compressed. Compressed resources can passAapt l -v Apk pathTo view the details of compression.
  • Use:
aaptOptions{
    // do not compress bat
	noCompress '.bat'
}
Copy the code

Before enabling compression, files with the “bat” suffix are compressed by default. As shown below, it is usedDEFLATEAlgorithm for compression, compression ratio of 11%.After compression is disabled, you can see that the same file has been converted to store, with a compression ratio of 0%

Write at the end

Github portal Gradle project address: Github portal

For aaptOptions configuration in this post, please enter the portal

If you find this post inspiring or confusing, give it a thumbs up or follow us, and kids will continue to share more great articles.

Or invite me to have a cup of coffee, children will be more confident to write