Home | History | Annotate | Download | only in gradle
      1 /**
      2  * This script plugin is used to build and dist the test APK outputs of a library with multiple
      3  * build flavors.
      4  *
      5  * Compared to the defaults of the 'dist' plugin, it does two additional things:
      6  * 1. It builds the "debug" test APKs when the 'dist' task is run.
      7  * 2. It dist the test APKs using the original output file name instead of hard coding
      8  *    "${project.archivesBaseName}Tests.apk". This allows multiple flavors of test APKs to be built
      9  *    without conflicting file names.
     10  */
     11 
     12 apply plugin: 'dist'
     13 
     14 // Set the dist files to empty map, and to tell DistExtension to not include the default files,
     15 // because the default output only supports one test APK output for libraries.
     16 dist.files = [:]
     17 android.testVariants.all { variant ->
     18     // "Debug" tests are not built by BuildSrc by default. Depend on the task so it will be built.
     19     tasks.dist.dependsOn variant.assemble
     20 
     21     // Output all test APKs to the distribution folder.
     22     // For a project named "setup-wizard-lib" with build flavor "platform" and build type "debug",
     23     // the output file will be named "setup-wizard-lib-platform-debug-androidTest.apk"
     24     variant.outputs.each { output ->
     25         dist.file output.outputFile.canonicalPath, output.outputFile.name
     26     }
     27 }
     28 android.libraryVariants.all { variant ->
     29     // Output all library AARs to the distribution folder
     30     variant.outputs.each { output ->
     31         dist.file output.outputFile.canonicalPath, output.outputFile.name
     32     }
     33 }
     34