使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Plugin for Gradle,修订版 1.3.0(2015 年 7 月)
依赖项:
|
最低版本 |
默认版本 |
备注 |
Gradle |
2.2.1 |
2.2.1 |
如需了解详情,请参阅更新 Gradle。 |
SDK Build Tools |
21.1.1 |
21.1.1 |
安装或配置 SDK Build Tools。 |
一般说明:
-
添加了对 com.android.build.threadPoolSize
属性的支持,可通过 gradle.properties
文件或命令行控制 Android
任务线程池的大小。以下示例会将此属性设置为 4。
-Pcom.android.build.threadPoolSize=4
- 将默认构建行为设置为从 APK 中排除
LICENSE
和 LICENSE.txt
文件。如需在 APK 中加入这些文件,请从 build.gradle
文件的 packagingOptions.excludes
属性中移除这些文件。例如:
android {
packagingOptions.excludes = []
}
android {
packagingOptions.excludes.clear()
}
- 添加了
sourceSets
任务,可检查所有可用源代码集的集合。
- 增强了对单元测试的支持,可识别多变种和 build 变体源代码文件夹。例如,如需测试配置了多变种(
flavor1
和 flavorA
)和 Debug
build 类型的应用,测试源代码集如下:
- test
- testFlavor1
- testFlavorA
- testFlavor1FlavorA
- testFlavor1FlavorADebug
Android 测试已经识别出多变种源代码文件夹。
- 改进了单元测试支持,以实现以下目的:
- 即使在 build 文件中将
useJack
属性设置为 true
,也可以在主要和测试源代码上运行 javac
。
- 正确识别每种 build 类型的依赖项。
- 添加了对从命令行指定插桩测试运行程序参数的支持。例如:
./gradlew connectedCheck
-Pandroid.testInstrumentationRunnerArguments.size=medium
-Pandroid.testInstrumentationRunnerArguments.class=TestA,TestB
在 build.gradle
文件中添加了对任意其他 Android 资源打包工具 (AAPT) 参数的支持。例如:
android {
aaptOptions {
additionalParameters "--custom_option", "value"
}
}
android {
aaptOptions {
additionalParameters += listOf("--custom_option", "value")
}
}
- 添加了对测试 APK 模块的支持,可作为单独的测试模块,并使用
targetProjectPath
和 targetVariant
属性来设置 APK 路径和目标变体。
注意:测试 APK 模块不支持产品变种,只能以单个变体为目标。此外,尚不支持 Jacoco。
- 在合并资源之前添加了资源名称验证。
- 在为库模块构建 AAR (Android ARchive) 软件包时,不要在清单合并程序设置中提供自动
@{applicationId}
占位符。相反,如果您要在归档库中包含应用 ID,请使用其他占位符(例如 @{libApplicationId}
)并为其提供值。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-30。
[null,null,["最后更新时间 (UTC):2025-08-30。"],[],[],null,["\u003cbr /\u003e\n\nAndroid plugin for Gradle, revision 1.3.0 (July 2015)\n\n**Dependencies:**\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:----------------------------------------------------------------------------------------------------------:|\n| Gradle | 2.2.1 | 2.2.1 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). |\n| SDK Build Tools | 21.1.1 | 21.1.1 | [Install](/studio/intro/update#sdk-manager) or [configure](/tools/releases/build-tools) SDK Build Tools. |\n\n**General Notes:**\n\n- Added support for the `com.android.build.threadPoolSize`\n property to control the `Android` task thread pool size from\n the `gradle.properties` file or the command line. The\n following example sets this property to 4.\n\n \n -Pcom.android.build.threadPoolSize=4\n \n \n- Set the default build behavior to exclude `LICENSE` and `LICENSE.txt` files from APKs. To include these files in an APK, remove these files from the `packagingOptions.excludes` property in the `build.gradle` file. For example: \n\n ```groovy\n android {\n packagingOptions.excludes = []\n }\n \n ``` \n\n ```kotlin\n android {\n packagingOptions.excludes.clear()\n }\n \n ```\n- Added the `sourceSets` task to inspect the set of all available source sets.\n- Enhanced unit test support to recognize multi-flavor and [build variant](/tools/building/configuring-gradle#workBuildVariants) source folders. For example, to test an app with multi-flavors `flavor1` and `flavorA` with the `Debug` build type, the test source sets are:\n - test\n - testFlavor1\n - testFlavorA\n - testFlavor1FlavorA\n - testFlavor1FlavorADebug\n\n Android tests already recognized multi-flavor source folders.\n- Improved unit test support to:\n - Run `javac` on main and test sources, even if the `useJack` property is set to `true` in your build file.\n - Correctly recognize dependencies for each build type.\n- Added support for specifying instrumentation test-runner arguments from the command line. For example: \n\n ```\n ./gradlew connectedCheck \n\n -Pandroid.testInstrumentationRunnerArguments.size=medium \n\n -Pandroid.testInstrumentationRunnerArguments.class=TestA,TestB\n \n ```\n- Added support for arbitrary additional Android Asset Packaging Tool (AAPT) parameters\n in the `build.gradle` file. For example:\n\n ```groovy\n android {\n aaptOptions {\n additionalParameters \"--custom_option\", \"value\"\n }\n }\n \n ``` \n\n ```kotlin\n android {\n aaptOptions {\n additionalParameters += listOf(\"--custom_option\", \"value\")\n }\n }\n \n ```\n- Added support for a [test APK module](/tools/studio/studio-features#test-module) as a separate test module, using the `targetProjectPath` and `targetVariant` properties to set the APK path and target variant.\n\n **Note:** A test APK module does not support product\n flavors and can only target a single variant. Also, Jacoco is not supported yet.\n- Added resource name validation before merging resources.\n- When building an AAR (Android ARchive) package for library modules, do not provide an automatic `@{applicationId}` placeholder in the [manifest merger](/tools/building/manifest-merge) settings. Instead, use a different placeholder, such as `@{libApplicationId}` and provide a value for it if you want to include application Ids in the archive library.\n\n\u003cbr /\u003e"]]