官术网_书友最值得收藏!

Using the Gradle build tool

During our development, we will need to build different build variants or run tests. Those tests can be executed for only certain build variants, if needed, or for all of them.

In the following examples, we will cover some of the most common Gradle use cases. We will start with cleaning and building.

As you remember, the Journaler application has the following build types defined:

  • debug
  • release
  • staging
  • preproduction

The following build flavors are also defined in the Journaler application:

  • demo
  • complete
  • special

Open terminal. To remove everything we built so far, and all temporally build derivates, execute the following command line:

./gradlew clean

It takes some time to do the cleaning. Then execute the following command line:

./gradlew assemble.

This assembles everything--all the build variants that we have in our application. Imagine the time impact it can have if we are dealing with a really big project. Therefore, we will isolate the build command. To build only the debug build type, execute the following command line:

./gradlew assembleDebug    

It will be executed much faster than the previous example! This builds all flavors for the debug build type. In order to be more effective, we will instruct Gradle that we are interested only in a complete build flavor for the debug build type. Execute this:

./gradlew assembleCompleteDebug

This executes much faster. Here, we will mention several more important Gradle commands that are useful:

To run all unit tests execute:

./gradlew test 

In case you want to run unit tests for a specific build variant, execute this command:

./gradlew testCompleteDebug

In Android, we can run tests on a real device instance or an emulator. Usually, those tests have access to some of Android's components. To execute those (instrumentation) tests, you can use the command shown in the following example:

./gradlew connectedCompleteDebug

You will find more about tests and testing Android applications in the final chapters of this book.

主站蜘蛛池模板: 于田县| 文化| 苍山县| 辉县市| 马鞍山市| 襄汾县| 东乌珠穆沁旗| 伊宁市| 新龙县| 新乡县| 孟村| 禹州市| 阜宁县| 平罗县| 上蔡县| 长武县| 绥中县| 兴业县| 垣曲县| 西峡县| 同德县| 绍兴县| 饶平县| 迁安市| 丰城市| 拉萨市| 财经| 呼和浩特市| 札达县| 扶余县| 石林| 格尔木市| 紫阳县| 奉节县| 青神县| 鹿邑县| 怀仁县| 昔阳县| 城固县| 盐源县| 松滋市|