透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Gradle 適用的 Android 外掛程式,修訂版本 1.3.0 (2015 年 7 月)
依附元件:
|
最低版本 |
預設版本 |
附註 |
Gradle |
2.2.1 |
2.2.1 |
詳情請參閱「更新 Gradle」一節。 |
SDK 版本工具 |
21.1.1 |
21.1.1 |
安裝或設定 SDK 版本工具。 |
一般注意事項:
-
新增對 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
工作,以便檢查所有可用的來源集。
- 加強單元測試支援,識別多個變種版本和建構變化版本的來源資料夾。舉例來說,如果想測試有多個變種版本
flavor1
和 flavorA
,建構類型為 Debug
的應用程式,測試來源集為:
- test
- testFlavor1
- testFlavorA
- testFlavor1FlavorA
- testFlavor1FlavorADebug
Android 測試已辨識到多個變種版本的來源資料夾。
- 改善單元測試支援,以便執行以下作業:
- 對主要和測試來源執行
javac
,即使建構檔案中的 useJack
屬性設為 true
也一樣。
- 正確識別每種建構類型的依附元件。
- 新增透過指令列指定檢測設備測試執行工具引數的支援功能。例如:
./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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-30 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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"]]