blob: 291dac23eabf35310700d2424bfa77559d3626c6 [file] [log] [blame]
Alan Viverette9562a3b2016-07-01 13:26:39 -04001import android.support.doclava.DoclavaMultilineJavadocOptionFileOption
Yigit Boyarea5d9b22016-03-08 13:25:26 -08002import com.android.build.gradle.internal.coverage.JacocoReportTask
3import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask
4
Alan Viverettecc5197e2016-06-13 12:45:07 -04005import android.support.checkapi.CheckApiTask
6import android.support.checkapi.UpdateApiTask
7import android.support.doclava.DoclavaTask
8
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08009buildscript {
10 repositories {
11 maven { url '../../prebuilts/gradle-plugin' }
12 maven { url '../../prebuilts/tools/common/m2/repository' }
13 maven { url '../../prebuilts/tools/common/m2/internal' }
Yigit Boyarc9750a12016-01-06 17:28:55 -080014 maven { url "../../prebuilts/maven_repo/android" }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080015 }
16 dependencies {
Justin Klaassenc1e50452016-07-13 17:36:16 -070017 classpath 'com.android.tools.build:gradle:2.2.0-alpha6'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080018 }
19}
20
Alan Viverettecc5197e2016-06-13 12:45:07 -040021repositories {
22 maven { url '../../prebuilts/tools/common/m2/repository' }
23}
24
25configurations {
26 doclava
27}
28
29dependencies {
30 doclava project(':doclava')
31}
32
Alan Viverettebbe3bae2016-07-14 12:30:42 -040033ext.supportVersion = '24.2.0-SNAPSHOT'
34ext.extraVersion = 35
Xavier Ducrohet020e4322014-03-18 16:41:30 -070035ext.supportRepoOut = ''
Yigit Boyarc9750a12016-01-06 17:28:55 -080036ext.buildToolsVersion = '23.0.2'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080037ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080038
Alan Viverettecc5197e2016-06-13 12:45:07 -040039// Enforce the use of prebuilt dependencies in all sub-projects. This is
40// required for the doclava dependency.
41ext.usePrebuilts = "true"
42
Xavier Ducrohet020e4322014-03-18 16:41:30 -070043/*
44 * With the build server you are given two env variables.
45 * The OUT_DIR is a temporary directory you can use to put things during the build.
46 * The DIST_DIR is where you want to save things from the build.
47 *
48 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
49 */
50if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070051 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
52 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080053
54 // the build server does not pass the build number so we infer it from the last folder of the dist path.
55 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070056} else {
Alan Viverette7b59d3a2016-06-13 12:52:20 -040057 buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build")
58 project.ext.distDir = file("${project.rootDir}/../../out/dist")
Xavier Ducrohet020e4322014-03-18 16:41:30 -070059}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080060
Alan Viverette9b5fe932016-07-22 10:28:31 -040061subprojects {
62 // Change buildDir first so that all plugins pick up the new value.
63 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
64}
65
Alan Viverettecc5197e2016-06-13 12:45:07 -040066ext.docsDir = new File(buildDir, 'javadoc')
Xavier Ducrohet020e4322014-03-18 16:41:30 -070067ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080068ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080069
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070070// Main task called by the build server.
71task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070072}
73
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070074// upload anchor for subprojects to upload their artifacts
75// to the local repo.
76task(mainUpload) << {
77}
78
79// repository creation task
80task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070081 from project.ext.supportRepoOut
82 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070083 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080084 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070085}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070086createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070087
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070088// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070089task unzipRepo(type: Copy) {
Alan Viverette7b59d3a2016-06-13 12:52:20 -040090 from "${project.rootDir}/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080091 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080092}
93
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070094unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070095 project.ext.supportRepoOut.deleteDir()
96 project.ext.supportRepoOut.mkdirs()
97}
98
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070099// anchor for prepare repo. This is post unzip + sourceProp.
100task(prepareRepo) << {
101}
102
Yigit Boyar3986e042016-02-08 18:31:38 -0800103
104import android.support.build.ApiModule
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700105import com.google.common.io.Files
106import com.google.common.base.Charsets
107
108task(createXml) << {
109 def repoArchive = createRepository.archivePath
110 def repoArchiveName = createRepository.archiveName
111 def size = repoArchive.length()
112 def sha1 = getSha1(repoArchive)
113
114 def xml =
115"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
116 <sdk:extra>\n\
117 <sdk:revision>\n\
118 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
119 </sdk:revision>\n\
120 <sdk:vendor-display>Android</sdk:vendor-display>\n\
121 <sdk:vendor-id>android</sdk:vendor-id>\n\
122 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
123 <sdk:path>m2repository</sdk:path>\n\
124 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -0800125 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700126 <sdk:size>${size}</sdk:size>\n\
127 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
128 <sdk:url>${repoArchiveName}</sdk:url>\n\
129 </sdk:archive>\n\
130 </sdk:archives>\n\
131 </sdk:extra>\n\
132</sdk:sdk-addon>"
133
134 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
135}
136createArchive.dependsOn createXml
137
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700138task(createSourceProp) << {
139 def sourceProp =
140"Extra.VendorDisplay=Android\n\
141Extra.Path=m2repository\n\
142Archive.Arch=ANY\n\
143Extra.NameDisplay=Android Support Repository\n\
144Archive.Os=ANY\n\
Alan Viverette5ae24d62016-04-06 16:17:13 -0400145Pkg.Desc=Local Maven repository for Support Libraries\n\
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700146Pkg.Revision=${project.ext.extraVersion}.0.0\n\
147Extra.VendorId=android"
148
149 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
150}
151createSourceProp.dependsOn unzipRepo
152prepareRepo.dependsOn createSourceProp
153
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700154import com.google.common.hash.HashCode
155import com.google.common.hash.HashFunction
156import com.google.common.hash.Hashing
Chris Banes96f1e912015-03-05 20:04:05 +0000157import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700158
Alan Viverettecc5197e2016-06-13 12:45:07 -0400159/**
160 * Generates SHA1 hash for the specified file's absolute path.
161 *
162 * @param inputFile file to hash
163 * @return SHA1 hash
164 */
165String getSha1(File inputFile) {
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700166 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000167 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700168 return hashCode.toString()
169}
170
Alan Viverettecc5197e2016-06-13 12:45:07 -0400171/**
172 * Returns the Android prebuilt JAR for the specified API level.
173 *
174 * @param apiLevel the API level or "current"
175 * @return a file collection containing the Android prebuilt JAR
176 */
Yigit Boyar9673b852016-06-14 11:13:32 -0700177FileCollection getAndroidPrebuilt(apiLevel) {
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400178 files("${project.rootDir}/../../prebuilts/sdk/$apiLevel/android.jar")
Alan Viverettecc5197e2016-06-13 12:45:07 -0400179}
180
181/**
182 * Populates the sub-project's set of source sets with the specified modules.
183 *
184 * @param subProject the sub-project to which the modules belong
185 * @param apiModules the modules from which to populate
186 */
187void createApiSourceSets(Project subProject, List<ApiModule> apiModules) {
Yigit Boyar3986e042016-02-08 18:31:38 -0800188 subProject.ext._apiModules = apiModules
189 subProject.ext.allSS = []
190 if (gradle.ext.studioCompat.enableApiModules) {
191 // nothing to do, they are all modules
192 return
193 }
194 // create a jar task for the api specific internal implementations
195 def internalJar = subProject.tasks.create(name: "internalJar", type: Jar) {
196 baseName "internal_impl"
197 }
198 apiModules.each { ApiModule apiModule ->
199 apiModule.sourceSet = createApiSourceset(subProject, apiModule.folderName, apiModule.folderName,
200 apiModule.apiForSourceSet.toString(), apiModule.prev == null ? null : apiModule.prev.sourceSet)
201 subProject.ext.allSS.add(apiModule.sourceSet)
202 }
203 subProject.android.libraryVariants.all { variant ->
204 variant.javaCompile.dependsOn internalJar
205 }
206}
207
Alan Viverettecc5197e2016-06-13 12:45:07 -0400208/**
209 * Adds the specified module to the sub-project's set of source sets and
210 * internal JAR. Also sets up dependencies, if supplied.
211 *
212 * @param subProject the sub-project to which the module belongs
213 * @param name the name of the module
214 * @param folder the module's source folder
215 * @param apiLevel the module's compile API level
216 * @param previousSource source set dependency (optional)
217 * @return a source set for the module
218 */
219SourceSet createApiSourceset(Project subProject, String name, String folder, String apiLevel,
Yigit Boyar3986e042016-02-08 18:31:38 -0800220 SourceSet previousSource) {
221 def sourceSet = subProject.sourceSets.create(name)
222 sourceSet.java.srcDirs = [folder]
223
224 def configName = sourceSet.getCompileConfigurationName()
225
226 subProject.getDependencies().add(configName, getAndroidPrebuilt(apiLevel))
227 if (previousSource != null) {
228 setupDependencies(subProject, configName, previousSource)
229 }
230 subProject.ext.allSS.add(sourceSet)
231 subProject.tasks.internalJar.from sourceSet.output
232 return sourceSet
233}
234
Alan Viverettecc5197e2016-06-13 12:45:07 -0400235/**
236 * Adds the specified source set as a dependency for the sub-project.
237 *
238 * @param subProject the sub-project to modify
239 * @param configName
240 * @param previousSourceSet the source set to add as a dependency
241 */
242void setupDependencies(Project subProject, String configName, SourceSet previousSourceSet) {
243 subProject.getDependencies().add(configName, previousSourceSet.output)
244 subProject.getDependencies().add(configName, previousSourceSet.compileClasspath)
245}
246
247void setApiModuleDependencies(Project subProject, DependencyHandler handler, List extraDeps) {
Yigit Boyar3986e042016-02-08 18:31:38 -0800248 if (gradle.ext.studioCompat.enableApiModules) {
249 subProject.android.enforceUniquePackageName=false
250 // add dependency on the latest module
251 handler.compile(project(subProject.ext._apiModules.last().moduleName))
252 } else {
253 handler.compile(files(subProject.tasks.internalJar.archivePath))
254 def firstModule = subProject.ext._apiModules[0]
255 extraDeps.each { dep ->
256 handler."${firstModule.folderName}Compile"(project(dep))
257 handler.compile(project(dep))
258 }
Yigit Boyar3986e042016-02-08 18:31:38 -0800259 }
260}
261
Alan Viverette9562a3b2016-07-01 13:26:39 -0400262void registerForDocsTask(Task task, Project subProject, releaseVariant) {
263 task.dependsOn releaseVariant.javaCompile
264 task.source {
Alan Viverettecc5197e2016-06-13 12:45:07 -0400265 def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir)
266 return releaseVariant.javaCompile.source.minus(buildConfig) +
267 fileTree(releaseVariant.aidlCompile.sourceOutputDir) +
268 fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir)
269 }
Alan Viverette9562a3b2016-07-01 13:26:39 -0400270 task.classpath += files(releaseVariant.javaCompile.classpath) +
Alan Viverettecc5197e2016-06-13 12:45:07 -0400271 files(releaseVariant.javaCompile.destinationDir)
272
273 if (subProject.hasProperty('allSS')) {
274 subProject.allSS.each { ss ->
Alan Viverette9562a3b2016-07-01 13:26:39 -0400275 task.source ss.java
Alan Viverettecc5197e2016-06-13 12:45:07 -0400276 }
277 }
278}
279
Alan Viverette9562a3b2016-07-01 13:26:39 -0400280// Generates online docs.
281task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) {
282 docletpath = configurations.doclava.resolve()
283 destinationDir = new File(project.docsDir, "online")
284
285 // Base classpath is Android SDK, sub-projects add their own.
286 classpath = getAndroidPrebuilt(gradle.ext.currentSdk)
287
288 def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf')
289 hdfOption.add(
290 ['android.whichdoc', 'online'],
291 ['android.hasSamples', 'true']);
292
293 options {
294 addStringOption "templatedir",
295 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
296 addStringOption "federate Android", "http://developer.android.com"
297 addStringOption "federationapi Android",
298 "${project.rootDir}/../../prebuilts/sdk/api/24.txt"
299 addStringOption "stubpackages", "android.support.*"
300 addStringOption "samplesdir", "${project.rootDir}/samples"
301 addOption hdfOption
302 }
303
304 exclude '**/BuildConfig.java'
305}
Alan Viverettecc5197e2016-06-13 12:45:07 -0400306
307// Generates API files.
308task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) {
309 docletpath = configurations.doclava.resolve()
310 destinationDir = project.docsDir
311
312 // Base classpath is Android SDK, sub-projects add their own.
313 classpath = getAndroidPrebuilt(gradle.ext.currentSdk)
314
315 apiFile = new File(project.docsDir, 'release/current.txt')
316 removedApiFile = new File(project.docsDir, 'release/removed.txt')
317 generateDocs = false
318
319 options {
320 addStringOption "templatedir",
321 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
322 addStringOption "federate Android", "http://developer.android.com"
323 addStringOption "federationapi Android",
324 "${project.rootDir}/../../prebuilts/sdk/api/24.txt"
325 addStringOption "stubpackages", "android.support.*"
326 }
327 exclude '**/BuildConfig.java'
328 exclude '**/R.java'
329}
330
331// Copies generated API files to current version.
332task updateApi(type: UpdateApiTask, dependsOn: generateApi) {
333 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400334 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400335 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400336 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400337}
338
339// Checks generated API files against current version.
340task checkApi(type: CheckApiTask, dependsOn: generateApi) {
341 doclavaClasspath = generateApi.docletpath
342
343 checkApiTaskPath = name
344 updateApiTaskPath = updateApi.name
345
346 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400347 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400348 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400349 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Yigit Boyar3986e042016-02-08 18:31:38 -0800350}
Alan Viverettedd377c92016-06-24 09:51:49 -0400351createArchive.dependsOn checkApi
Yigit Boyar3986e042016-02-08 18:31:38 -0800352
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800353subprojects {
Alan Viverettecc5197e2016-06-13 12:45:07 -0400354 // Only modify android projects.
355 if (project.name.equals('doclava')) return;
356
Yigit Boyar3986e042016-02-08 18:31:38 -0800357 // current SDK is set in studioCompat.gradle
358 project.ext.currentSdk = gradle.ext.currentSdk
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800359 apply plugin: 'maven'
Yigit Boyar3986e042016-02-08 18:31:38 -0800360 project.ext.createApiSourceSets = this.&createApiSourceset
361 project.ext.setApiModuleDependencies = this.&setApiModuleDependencies
362
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800363 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800364 group = 'com.android.support'
365
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700366 repositories {
367 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
368 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
369 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
370 }
371
Jeff Davidson84faec52014-06-18 09:10:36 -0700372 project.plugins.whenPluginAdded { plugin ->
Chris Banese17c5192016-06-01 13:36:05 +0100373 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
374 || "com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
Jeff Davidson84faec52014-06-18 09:10:36 -0700375 project.android.buildToolsVersion = rootProject.buildToolsVersion
Yigit Boyard8d42d52016-04-12 18:20:18 -0700376 // enable code coverage for debug builds only if we are not running inside the IDE
377 // enabling coverage reports breaks the method parameter resolution in the IDE debugger
378 project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide')
Jeff Davidson84faec52014-06-18 09:10:36 -0700379 }
Alan Viverette573630e2016-07-08 17:17:47 -0400380
381 // Create release and separate zip task for Android libraries (and android-annotations,
382 // which is just a Java library).
383 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
384 || "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)) {
385 task release(type: Upload) {
386 configuration = configurations.archives
387 repositories {
388 mavenDeployer {
389 repository(url: uri("$rootProject.ext.supportRepoOut"))
390
391 // Disable unique names for SNAPSHOTS so they can be updated in place.
392 setUniqueVersion(false)
393 doLast {
394 // Remove any invalid maven-metadata.xml files that may have been
395 // created for SNAPSHOT versions that are *not* uniquely versioned.
396 pom*.each { pom ->
397 if (pom.version.endsWith('-SNAPSHOT')) {
398 final File artifactDir = new File(
399 rootProject.ext.supportRepoOut,
400 pom.groupId.replace('.', '/')
401 + '/' + pom.artifactId
402 + '/' + pom.version)
403 delete fileTree(dir: artifactDir,
404 include: 'maven-metadata.xml*')
405 }
406 }
407 }
408 }
409 }
410 }
411
412 def deployer = release.repositories.mavenDeployer
413 deployer.pom*.whenConfigured { pom ->
414 pom.dependencies.findAll { dep ->
415 dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations'
416 }*.type = 'aar'
417 }
418
419 ext.versionDir = {
420 def groupDir = new File(rootProject.ext.supportRepoOut,
421 project.group.replace('.','/'))
422 def artifactDir = new File(groupDir, archivesBaseName)
423 return new File(artifactDir, version)
424 }
425
426 task generateSourceProps(dependsOn: createRepository) << {
427 def content = "Maven.GroupId=$deployer.pom.groupId\n" +
428 "Maven.ArtifactId=$deployer.pom.artifactId\n" +
429 "Maven.Version=$deployer.pom.version\n" +
430 "Pkg.Desc=$project.name\n" +
431 "Pkg.Revision=1\n" +
432 "Dependencies=" +
433 String.join(",", project.configurations.compile.allDependencies.collect {
434 def p = parent.findProject(it.name)
435 return p ? "$p.group:$p.archivesBaseName:$p.version" : null
436 }.grep()) +
437 "\n"
438 Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8)
439 }
440
441 task createSeparateZip(type: Zip, dependsOn: generateSourceProps) {
442 into archivesBaseName
443 destinationDir project.parent.ext.distDir
444 baseName = project.group
445 version = project.parent.ext.buildNumber
446 }
447 project.parent.createArchive.dependsOn createSeparateZip
448
449 // before the upload, make sure the repo is ready.
450 release.dependsOn rootProject.tasks.prepareRepo
451 // make the mainupload depend on this one.
452 mainUpload.dependsOn release
453 }
Jeff Davidson84faec52014-06-18 09:10:36 -0700454 }
Chris Banesdaea0692015-12-29 12:48:24 +0000455
Chris Banesdaea0692015-12-29 12:48:24 +0000456 project.afterEvaluate {
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700457 // The archivesBaseName isn't available intially, so set it now
Alan Viverette573630e2016-07-08 17:17:47 -0400458 def createZipTask = project.tasks.findByName("createSeparateZip")
459 if (createZipTask != null) {
460 createZipTask.appendix = archivesBaseName
461 createZipTask.from versionDir()
462 }
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700463
464 // Copy instrumentation test APK into the dist dir
Chris Banesdaea0692015-12-29 12:48:24 +0000465 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
466 if (assembleTestTask != null) {
467 assembleTestTask.doLast {
468 // If the project actually has some instrumentation tests, copy its APK
469 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
470 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
471 copy {
472 from(pkgTask.outputFile)
473 into(rootProject.ext.testApkDistOut)
474 }
475 }
476 }
477 }
478 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800479
480 project.afterEvaluate { p ->
481 // remove dependency on the test so that we still get coverage even if some tests fail
482 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
483 def toBeRemoved = new ArrayList()
484 def dependencyList = task.taskDependencies.values
485 dependencyList.each { dep ->
486 if (dep instanceof String) {
487 def t = tasks.findByName(dep)
488 if (t instanceof DeviceProviderInstrumentTestTask) {
489 toBeRemoved.add(dep)
490 task.mustRunAfter(t)
491 }
492 }
493 }
494 toBeRemoved.each { dep ->
495 dependencyList.remove(dep)
496 }
497 }
498 }
Alan Viverettecc5197e2016-06-13 12:45:07 -0400499
500 project.afterEvaluate { p ->
501 if (p.hasProperty('android')
502 && p.android.hasProperty('libraryVariants')
503 && !(p.android.hasProperty('noDocs') && p.android.noDocs)) {
504 p.android.libraryVariants.all { v ->
505 if (v.name == 'release') {
Alan Viverette9562a3b2016-07-01 13:26:39 -0400506 registerForDocsTask(rootProject.generateDocs, p, v)
507 registerForDocsTask(rootProject.generateApi, p, v)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400508 }
509 }
510 }
511 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800512}
513
Chris Banes9ae4ee82015-09-11 10:32:15 +1000514project.gradle.buildFinished { buildResult ->
515 if (buildResult.getFailure() != null) {
516 println()
517 println 'Build failed. Possible causes include:'
518 println ' 1) Bad codes'
519 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100520 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000521 println()
522 }
523}