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

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.

主站蜘蛛池模板: 德昌县| 庆城县| 繁昌县| 云安县| 德兴市| 永康市| 基隆市| 大方县| 福安市| 天镇县| 宁陕县| 平原县| 忻州市| 白朗县| 铜山县| 孟村| 武陟县| 景东| 西华县| 西畴县| 九江县| 平定县| 繁昌县| 额敏县| 容城县| 河源市| 山丹县| 彩票| 丰镇市| 霍邱县| 莆田市| 华池县| 渭源县| 秀山| 行唐县| 东丰县| 沂南县| 莱阳市| 淄博市| 武城县| 彩票|