connected to an in-depth Android Gradle build system (II: Project structure)
Build task (build tasks) Java and Android common tasks
An Android or Java plugin is used in the build file to automatically create a series of tasks that can be run.
The following tasks are the default conventions in Gradle:
1. Assemble
This task contains all the packaging-related tasks in the project, such as the jar package in the Java project, the APK that was hit in the Android project
2. Check
This task contains all the validation-related tasks in the project, such as the task of running the test
3. Build
This task contains the assemble and check
4. Clean
This task clears all output from the project and removes all packages that were hit in the assemble task.
Assemble, check and build tasks don't actually do anything, they just provide a hook for the plugin, and the real thing is done by the plugin.
In this way, developers don't have to worry about whether I'm running a Java project or an Android project, or what Gradle plug-ins I'm using, because I can call these agreed tasks to complete the build.
For example, using the FindBugs plugin creates a new task and makes the check task dependent on the newly created task, which executes the new task each time the check task is executed.
Executing at the command line
Gradle Tasks
</pre> will list all the major tasks if you want to see all the tasks and their dependencies, you can run: <pre name= "code" class= "Java" >gradle tasks--all
Note: Gradle automatically checks the input and output of a task. For example, if you run the build task twice in a row, Gradle will report that all the tasks are already up-to-date and do not need to be run again. In this way, tasks are interdependent and do not result in repetitive executions.
Java Project Common Tasks Java plugin primarily creates two tasks:
1. Jar
The assemble task depends on the jar task, and the name knows it is the task that is responsible for hitting the jar package. The jar task itself relies on many other tasks, such as the classes task, and the classes task compiles the Java code
2. Test
The check task relies on the test task, which runs all the tests. The test code compiles using the Testclasses task, but we don't have to run the Testclasses task manually because the test task has already added a dependency on it.
Normally, we just have to run assemble and check tasks.
Want to see all the tasks provided by the Java plugin and their dependencies can click this [link] (http://gradle.org/docs/current/userguide/java_plugin.html)
Android projects often use tasks like other Gradle plugins, and the Android plugin also provides some default tasks, such as Assemble,check,build,clean, and it also offers some of its own specific tasks, such as:
1. Connectedcheck
Run inspection tasks that need to be performed on a real machine or emulator that will run in parallel on all connected devices
2. Devicecheck
Use APIs to connect remote devices to perform checks. Primarily for CI (continuous integration) services.
Both of the above tasks perform assemble and check tasks. Adding these two tasks is necessary to ensure that we can run inspection tasks that do not require a connection to the device.
Note: The build task does not depend on Devicecheck or Connectedcheck
An Android project usually has at least two outputs: Debug apk and Release apk. There are two tasks in the corresponding gradle that can output different apk separately:
Assembledebug
Assemblerelease
These two tasks will also rely on other tasks to build an apk. The assemble task relies on both tasks, and invoking the assemble task will generate two apk types.
Tip: Gradle supports the use of camel-style abbreviations in the command line instead of task names, such as:
Gradle AR
Equivalent to
Gradle Assemblerelease
As long as there is no other task of the abbreviation is also ' AR '
dependencies for check-related tasks:
Check dependent lint
Connectedcheck dependent on connectedandroidtest and connecteduiautomatortest (not yet implemented)
Devicecheck relies on the tasks provided by plug-ins that implement the test extension
Finally, the Android Gradle plugin also offers install and uninstall tasks for installing and uninstalling APK
In layman's Android Gradle build system (III: Build Task)