Clone this repo:
  1. 69c4b95 Merge "Fix Build" by Josiah Gaskin · 3 years, 1 month ago l-preview lollipop-cts-release lollipop-dev lollipop-mr1-cts-release lollipop-mr1-dev lollipop-mr1-fi-release lollipop-mr1-release lollipop-mr1-wfc-release lollipop-release lollipop-wear-release marshmallow-cts-release marshmallow-dev marshmallow-dr-dev marshmallow-dr-dragon-release marshmallow-dr-release marshmallow-dr1.5-dev marshmallow-dr1.5-release marshmallow-dr1.6-release marshmallow-mr1-dev marshmallow-mr1-release marshmallow-mr2-release marshmallow-mr3-release marshmallow-release master master-soong n-iot-preview-2 n-iot-preview-4 nougat-cts-release nougat-dev nougat-dr1-release nougat-mr0.5-release nougat-mr1-cts-release nougat-mr1-dev nougat-mr1-release nougat-mr1-volantis-release nougat-mr1-wear-release nougat-mr1.1-release nougat-mr1.2-release nougat-mr1.3-release nougat-mr1.4-release nougat-mr1.5-release nougat-mr2-dev nougat-mr2-pixel-release nougat-mr2-release nougat-mr2.1-release nougat-mr2.2-release nougat-release sdk-release android-5.0.0_r1 android-5.0.0_r2 android-5.0.0_r3 android-5.0.0_r4 android-5.0.0_r5 android-5.0.0_r5.1 android-5.0.0_r6 android-5.0.0_r7 android-5.0.1_r1 android-5.0.2_r1 android-5.0.2_r3 android-5.1.0_r1 android-5.1.0_r3 android-5.1.0_r4 android-5.1.0_r5 android-5.1.1_r1 android-5.1.1_r10 android-5.1.1_r12 android-5.1.1_r13 android-5.1.1_r14 android-5.1.1_r15 android-5.1.1_r16 android-5.1.1_r17 android-5.1.1_r18 android-5.1.1_r19 android-5.1.1_r2 android-5.1.1_r20 android-5.1.1_r22 android-5.1.1_r23 android-5.1.1_r24 android-5.1.1_r25 android-5.1.1_r26 android-5.1.1_r28 android-5.1.1_r29 android-5.1.1_r3 android-5.1.1_r30 android-5.1.1_r33 android-5.1.1_r34 android-5.1.1_r35 android-5.1.1_r36 android-5.1.1_r37 android-5.1.1_r38 android-5.1.1_r4 android-5.1.1_r5 android-5.1.1_r6 android-5.1.1_r7 android-5.1.1_r8 android-5.1.1_r9 android-6.0.0_r1 android-6.0.0_r11 android-6.0.0_r12 android-6.0.0_r13 android-6.0.0_r2 android-6.0.0_r23 android-6.0.0_r24 android-6.0.0_r25 android-6.0.0_r26 android-6.0.0_r3 android-6.0.0_r4 android-6.0.0_r41 android-6.0.0_r5 android-6.0.0_r6 android-6.0.0_r7 android-6.0.1_r1 android-6.0.1_r10 android-6.0.1_r11 android-6.0.1_r12 android-6.0.1_r13 android-6.0.1_r16 android-6.0.1_r17 android-6.0.1_r18 android-6.0.1_r20 android-6.0.1_r21 android-6.0.1_r22 android-6.0.1_r24 android-6.0.1_r25 android-6.0.1_r26 android-6.0.1_r27 android-6.0.1_r28 android-6.0.1_r3 android-6.0.1_r30 android-6.0.1_r31 android-6.0.1_r32 android-6.0.1_r33 android-6.0.1_r4 android-6.0.1_r40 android-6.0.1_r41 android-6.0.1_r42 android-6.0.1_r43 android-6.0.1_r45 android-6.0.1_r46 android-6.0.1_r47 android-6.0.1_r48 android-6.0.1_r49 android-6.0.1_r5 android-6.0.1_r50 android-6.0.1_r51 android-6.0.1_r52 android-6.0.1_r53 android-6.0.1_r54 android-6.0.1_r55 android-6.0.1_r56 android-6.0.1_r57 android-6.0.1_r58 android-6.0.1_r59 android-6.0.1_r60 android-6.0.1_r61 android-6.0.1_r62 android-6.0.1_r63 android-6.0.1_r65 android-6.0.1_r66 android-6.0.1_r67 android-6.0.1_r68 android-6.0.1_r69 android-6.0.1_r7 android-6.0.1_r70 android-6.0.1_r72 android-6.0.1_r73 android-6.0.1_r74 android-6.0.1_r77 android-6.0.1_r78 android-6.0.1_r79 android-6.0.1_r8 android-6.0.1_r9 android-7.0.0_r1 android-7.0.0_r12 android-7.0.0_r13 android-7.0.0_r14 android-7.0.0_r15 android-7.0.0_r17 android-7.0.0_r19 android-7.0.0_r21 android-7.0.0_r24 android-7.0.0_r27 android-7.0.0_r28 android-7.0.0_r29 android-7.0.0_r3 android-7.0.0_r30 android-7.0.0_r31 android-7.0.0_r32 android-7.0.0_r33 android-7.0.0_r4 android-7.0.0_r5 android-7.0.0_r6 android-7.0.0_r7 android-7.1.0_r1 android-7.1.0_r2 android-7.1.0_r3 android-7.1.0_r4 android-7.1.0_r5 android-7.1.0_r6 android-7.1.0_r7 android-7.1.1_r1 android-7.1.1_r10 android-7.1.1_r11 android-7.1.1_r12 android-7.1.1_r13 android-7.1.1_r14 android-7.1.1_r15 android-7.1.1_r16 android-7.1.1_r17 android-7.1.1_r2 android-7.1.1_r20 android-7.1.1_r21 android-7.1.1_r22 android-7.1.1_r23 android-7.1.1_r24 android-7.1.1_r25 android-7.1.1_r26 android-7.1.1_r27 android-7.1.1_r28 android-7.1.1_r3 android-7.1.1_r31 android-7.1.1_r32 android-7.1.1_r33 android-7.1.1_r35 android-7.1.1_r38 android-7.1.1_r39 android-7.1.1_r4 android-7.1.1_r40 android-7.1.1_r41 android-7.1.1_r42 android-7.1.1_r43 android-7.1.1_r6 android-7.1.1_r7 android-7.1.1_r8 android-7.1.1_r9 android-7.1.2_r1 android-7.1.2_r10 android-7.1.2_r11 android-7.1.2_r12 android-7.1.2_r13 android-7.1.2_r14 android-7.1.2_r15 android-7.1.2_r16 android-7.1.2_r17 android-7.1.2_r2 android-7.1.2_r3 android-7.1.2_r4 android-7.1.2_r5 android-7.1.2_r6 android-7.1.2_r8 android-7.1.2_r9 android-cts-5.0_r3 android-cts-5.0_r4 android-cts-5.0_r5 android-cts-5.0_r6 android-cts-5.0_r7 android-cts-5.0_r8 android-cts-5.0_r9 android-cts-5.1_r1 android-cts-5.1_r10 android-cts-5.1_r13 android-cts-5.1_r14 android-cts-5.1_r15 android-cts-5.1_r16 android-cts-5.1_r17 android-cts-5.1_r18 android-cts-5.1_r19 android-cts-5.1_r2 android-cts-5.1_r20 android-cts-5.1_r3 android-cts-5.1_r4 android-cts-5.1_r5 android-cts-5.1_r6 android-cts-5.1_r7 android-cts-5.1_r8 android-cts-5.1_r9 android-cts-6.0_r1 android-cts-6.0_r12 android-cts-6.0_r13 android-cts-6.0_r14 android-cts-6.0_r15 android-cts-6.0_r16 android-cts-6.0_r17 android-cts-6.0_r18 android-cts-6.0_r19 android-cts-6.0_r2 android-cts-6.0_r3 android-cts-6.0_r5 android-cts-6.0_r6 android-cts-6.0_r7 android-cts-6.0_r8 android-cts-6.0_r9 android-cts-7.0_r1 android-cts-7.0_r10 android-cts-7.0_r2 android-cts-7.0_r3 android-cts-7.0_r4 android-cts-7.0_r5 android-cts-7.0_r6 android-cts-7.0_r7 android-cts-7.0_r8 android-cts-7.0_r9 android-cts-7.1_r1 android-cts-7.1_r2 android-cts-7.1_r3 android-cts-7.1_r4 android-cts-7.1_r5 android-cts-7.1_r6 android-l-preview_r2 android-m-preview android-m-preview-1 android-m-preview-2 android-n-iot-preview-2 android-n-iot-preview-4 android-n-mr1-preview-1 android-n-mr1-preview-2 android-n-mr2-preview-1 android-n-mr2-preview-2 android-n-preview-1 android-n-preview-2 android-n-preview-3 android-n-preview-4 android-n-preview-5 android-o-preview-2 android-wear-5.0.0_r1 android-wear-5.1.0_r1 android-wear-5.1.1_r1 android-wear-7.1.1_r1 android-wear-n-preview-1 android-wear-n-preview-2 android-wear-o-preview-3
  2. 6230f85 Fix Build by Josiah Gaskin · 3 years, 1 month ago
  3. ef84df9 Merge "Proguard information in readme file was outdated" by Xavier Ducrohet · 3 years, 4 months ago idea133-weekly-release
  4. 337438e Merge "Refactor build logic." by Xavier Ducrohet · 3 years, 7 months ago idea133
  5. 1584794 Refactor build logic. by Xavier Ducrohet · 3 years, 7 months ago

What is this?

The official Gradle plugin to build Android applications.

DSL

The plugin adds several concepts to the Gradle DSL, all in the android extension:

  • A default config. This lets you configure default values for your application.
  • A product flavor. For example, a free or a paid-for flavour.
  • A build type. There are 2 predefined build types, called release and debug. You can add additional build types.

If you do not define any flavors for your product, only the values from the default config are used. Flavor settings override the default config.

From this, the plugin will add the appropriate tasks to build each combination of build type and product flavor. The plugin will also define the following source directories:

  • src/main/java - Java source to be included in all application variants.
  • src/main/res - Resources to be included in all application variants.
  • `src/main/AndroidManifest.xml' - The application manifest (currently shared by all application variants).
  • src/$BuildType/java - Java source to be included in all application variants with the given build type.
  • src/$BuildType/res - Java source to be included in all application variants with the given build type.
  • src/$ProductFlavor/java - Resources to be included in all application variants with the given product flavor.
  • src/$ProductFlavor/res - Resources to be included in all application variants with the given product flavor.
  • src/test/java - Test source to be included in all test applications.
  • src/test$ProductFlavor/java - Test source to be include for the test application for the given product flavor.

You can configure these locations by configuring the associated source set provided by the android extension.

Compile time dependencies are declared in the usual way.

Have a look at the tests/basic/build.gradle build file and other projects in tests customized/build.gradle to see the DSL in action.

Configuration options

  • android.target - required.
  • android.defaultConfig.versionCode - defaults to that specified in src/main/AndroidManifest.xml
  • android.defaultConfig.versionName - defaults to that specified in src/main/AndroidManifest.xml
  • android.productFlavors.$flavor.packageName - defaults to that specified in src/main/AndroidManifest.xml
  • android.productFlavors.$flavor.versionCode - defaults to ${android.defaultConfig.versionCode}
  • android.productFlavors.$flavor.versionName - defaults to ${android.defaultConfig.versionName}
  • android.buildTypes.$type.zipAlign - defaults to true for release and false for debug
  • android.sourceSets.main.java.srcDirs - defaults to src/main/java
  • android.sourceSets.main.resources.srcDirs - defaults to src/main/res
  • android.sourceSets.$flavor.java.srcDirs - defaults to src/$flavor/java
  • android.sourceSets.$flavor.resources.srcDirs - defaults to src/$flavor/res
  • android.sourceSets.$buildType.java.srcDirs - defaults to src/$buildType/java
  • android.sourceSets.$buildType.resources.srcDirs - defaults to src/$buildType/res
  • android.sourceSets.test.java.srcDirs - defaults to src/test/java
  • android.sourceSets.test$Flavor.java.srcDirs - defaults to src/test$Flavor/java
  • dependencies.compile - compile time dependencies for all applications.

Contents

The source tree contains the following:

  • The builder directory contains the builder library.
  • The gradle directory contains the plugin implementation.
  • The tests directory contains various test applications used both as samples and tests by the plugin build system.

Usage

To build the plugin, run ./gradlew uploadArchives

To build the plugin for release, removing the SNAPSHOT from the version, run ./gradlew --init-script release.gradle <tasks>

To import the plugin into the IDE, run ./gradlew idea or ./gradlew eclipse.

To build a test application:

  1. cd into the root directory of the test application.
  2. Edit the local.properties file to point at your local install of the Android SDK. Normally, these files would not be checked into source control, but would be generated when the project is bootstrapped.
  3. Run ../../gradlew tasks to see the tasks that are available.

You can also run these tasks:

  • assemble - builds all combinations of build type and product flavor
  • assemble$BuildType - build all flavors for the given build type.
  • assemble$ProductFlavor - build all build types for the given product flavor.
  • assemble$ProductFlavor$BuildType - build the given application variant.
  • install$ProductFlavor$BuildType - build and install the given application variant.

Implementation

For each variant (product-flavor, build-type):

  • Generates resource source files into build/source from resource directories (main-source-set, product-flavor-source-set, build-type-source-set)
  • Compile source files (main-source-set, product-flavor-source-set, build-type-source-set, generated-source).
  • Converts the bytecode into build/libs
  • Crunches resources in build/resources
  • Packages the resource into build/libs
  • Assembles the application package into build/libs.