文章摘要
1、 Gradle 任務(wù)列表
2、構(gòu)建調(diào)式APK
一、Gradle 任務(wù)
您可以使用 Gradle 包裝器命令行工具執(zhí)行您的 Android 項(xiàng)目中可用的所有構(gòu)建任務(wù)。它可作為 Windows 的批處理文件 (gradlew.bat) 和 Linux 與 Mac 的 shell 腳本文件 (gradlew.sh) 使用,可以從您使用 Android Studio 創(chuàng)建的每個(gè)項(xiàng)目的根獲取。
要使用包裝器運(yùn)行任務(wù),請(qǐng)使用下列命令之一:
- 在 Windows 上:
gradlew task-name
- 在 Mac 或 Linux 上:
./gradlew task-name
要查看您的項(xiàng)目所有可用構(gòu)建任務(wù)的列表,請(qǐng)執(zhí)行 tasks:
gradlew tasks
附:
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for each variant.
sourceSets - Prints out all the source sets defined in this project.
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
cleanBuildCache - Deletes the build cache directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources
extractDebugAnnotations - Extracts Android annotations for the debug variant into the archive file
extractReleaseAnnotations - Extracts Android annotations for the release variant into the archive file
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'UsingDemosSample'.
components - Displays the components produced by root project 'UsingDemosSample'. [incubating]
dependencies - Displays all dependencies declared in root project 'UsingDemosSample'.
dependencyInsight - Displays the insight into a specific dependency in root project 'UsingDemosSample'.
dependentComponents - Displays the dependent components of components in root project 'UsingDemosSample'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'UsingDemosSample'. [incubating]
projects - Displays the sub-projects of root project 'UsingDemosSample'.
properties - Displays the properties of root project 'UsingDemosSample'.
tasks - Displays the tasks runnable from root project 'UsingDemosSample' (some of the displayed tasks may belong to subprojects).
Install tasks
-------------
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.
Verification tasks
------------------
check - Runs all checks.
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
lint - Runs lint on all variants.
lintDebug - Runs lint on the Debug build.
lintRelease - Runs lint on the Release build.
test - Run unit tests for all variants.
testDebugUnitTest - Run unit tests for the debug build.
testReleaseUnitTest - Run unit tests for the release build.
二、構(gòu)建調(diào)試 APK
要想立即測(cè)試和調(diào)試應(yīng)用,您可以構(gòu)建調(diào)試 APK。調(diào)試 APK 通過(guò) SDK 工具提供的調(diào)試密鑰簽署,并允許通過(guò) adb 調(diào)試。
要構(gòu)建調(diào)試 APK,請(qǐng)打開(kāi)命令行,然后導(dǎo)航至項(xiàng)目目錄的根 - 在 Android Studio 中,選擇 View > Tool Windows > Terminal。要啟動(dòng)調(diào)試構(gòu)建,請(qǐng)調(diào)用 assembleDebug 任務(wù):
gradlew assembleDebug
這將在 project_name/module_name/build/outputs/apk/ 中創(chuàng)建一個(gè)名稱(chēng)為 module_name-debug.apk 的 APK。此文件已通過(guò)調(diào)試密鑰簽署,并與 zipalign 對(duì)齊,因此,您可以在設(shè)備上立即安裝。
或者要構(gòu)建 APK,并立即在運(yùn)行的模擬器或連接的設(shè)備上安裝,請(qǐng)改為調(diào)用 installDebug:
gradlew installDebug
上述任務(wù)名稱(chēng)中的“調(diào)試”部分僅僅是構(gòu)建變體名稱(chēng)的駱駝拼寫(xiě)法版本,因此,可以使用您想要匯編或安裝的任何構(gòu)建變體替換。例如,如果您有“演示”產(chǎn)品風(fēng)味,則可以過(guò) assembleDemoDebug 任務(wù)構(gòu)建調(diào)試版本。
要查看每個(gè)變體可用的所有構(gòu)建和安裝任務(wù)(包括卸載任務(wù)),請(qǐng)運(yùn)行 tasks 任務(wù)。