note:

  1. This is a continuously improving document. If you have any questions, comments or suggestions, please leave a comment to me and I will make corrections.
  2. In this series, you won’t start out with some Groovy related concepts, but rather follow the project as it comes along.
  1. Introduction to the
  2. The preparatory work
  3. About the Task

Ok, so that’s our first step into this project. Create a new Android project. We will implement our packaging tool step by step based on this project. I’ll call this project GradleTest here.

By default, Gradle gives me tasks that look like this:

As you can see, Gradle already creates many tasks for us by default. And these tasks are grouped.

These tasks depend on each other and are executed in a specified order, and when the last task is executed, the entire build process is completed.

Click on the “Build” group under “:app” and you’ll see a bunch of tasks. This group consists mainly of build-related tasks, such as:

  1. AssembleRelease builds a release
  2. AssembleDebug builds the debug version

There are two ways to perform these tasks:

  1. Double-click the task directly in the Android Gradle panel.
  2. By executing the command on the command line.

Note: I then typically view and launch these tasks in Android Studio

Next we create two tasks of our own:

  1. PublishRelease: Publishes the release version
  2. PublishDebug: Publishes the debug version

Add the following code to the “build.gralde” file in the “app” module:

task publishRelease(a) {}task publishDebug(a) {}Copy the code

After the addition, we can view the two tasks in the Gradle panel in Android Studio:

GradleTest-> App ->Tasks-> Other -> GradleTest-> App ->Tasks-> Other The diagram below:

So many tasks, we always find these two tasks like this, it is too troublesome, we can group these two tasks, in the “app” module “build.gradle” file add the following code:

task publishRelease(a) {
    group "publish"
}

task publishDebug(a) {
    group "publish"
}Copy the code

These two lines of code divide the two tasks into a “publish” group. The diagram below:

So far, we have done the preparatory work.