gradle 编译命令

Android Studio的项目中自带了gradle 编译环境,如下图:

gradle wrapper 避免了gradle 因版本不同引发的种种问题,使你不用在本地安装gradle 就可以执行编译命令。

  1. server:CardViewSample samzhao$ ./gradlew clean assemble

    先清理以前编译过的文件再编译,耗时最长。我这次编译用了

    BUILD SUCCESSFUL

    Total time: 32.394 secs

  2. server:CardViewSample samzhao$ ./gradlew assemble

    不清理,采用以前编译好的,不需要重新编译的文件进行编译。许多编译项目后面都跟有UP-TO-DATE,如:
    :app:compileDebugAidl UP-TO-DATE
    这主要是更新了文件的时间戳,没有进行重新编译。这次时间明显减少了:

    BUILD SUCCESSFUL

    Total time: 8.394 secs

  3. server:CardViewSample samzhao$ ./gradlew assemble --daemon

    加上--daemon后缀就不用每次编译时都把gradle重新加载到内存了,第一次用--daemon,编译时间还是8秒多,但第二次运行就快很多了,如下:

    BUILD SUCCESSFUL

    Total time: 4.021 secs

编译好的apk在如下位置:

其实cleanassemble都是gradletask

查询tasks,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
server:CardViewSample samzhao$ ./gradlew -q 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
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleDebug - Assembles all Debug builds
assembleDebugTest - Assembles the Test build for the Debug build
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.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
dependencies - Displays all dependencies declared in root project 'CardViewSample'.
dependencyInsight - Displays the insight into a specific dependency in root project 'CardViewSample'.
help - Displays a help message
projects - Displays the sub-projects of root project 'CardViewSample'.
properties - Displays the properties of root project 'CardViewSample'.
tasks - Displays the tasks runnable from root project 'CardViewSample' (some of the displayed tasks may belong to subprojects).
Install tasks
-------------
installDebug - Installs the Debug build
installDebugTest - Installs the Test build for the Debug build
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build
uninstallDebugTest - Uninstalls the Test build for the Debug build
uninstallRelease - Uninstalls the Release build
Verification tasks
------------------
check - Runs all checks.
connectedAndroidTest - Installs and runs the tests for Build 'debug' on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
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
To see all tasks and more detail, run with --all.
server:CardViewSample samzhao$

参考链接:

http://blog.stylingandroid.com/tag/gradle-2/