1 buildscript { 2 repositories { 3 maven { url '../../prebuilts/gradle-plugin' } 4 maven { url '../../prebuilts/tools/common/m2/repository' } 5 maven { url '../../prebuilts/tools/common/m2/internal' } 6 } 7 dependencies { 8 classpath 'com.android.tools.build:gradle:1.3.1' 9 } 10 } 11 12 ext.supportVersion = '23.0.0' 13 ext.extraVersion = 17 14 ext.supportRepoOut = '' 15 ext.buildToolsVersion = '22.1.0' 16 ext.buildNumber = Integer.toString(ext.extraVersion) 17 18 /* 19 * With the build server you are given two env variables. 20 * The OUT_DIR is a temporary directory you can use to put things during the build. 21 * The DIST_DIR is where you want to save things from the build. 22 * 23 * The build server will copy the contents of DIST_DIR to somewhere and make it available. 24 */ 25 if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { 26 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() 27 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() 28 29 // the build server does not pass the build number so we infer it from the last folder of the dist path. 30 ext.buildNumber = project.ext.distDir.getName() 31 } else { 32 buildDir = file('../../out/host/gradle/frameworks/support/build') 33 project.ext.distDir = file('../../out/dist') 34 } 35 36 ext.supportRepoOut = new File(buildDir, 'support_repo') 37 38 // Main task called by the build server. 39 task(createArchive) << { 40 } 41 42 43 // upload anchor for subprojects to upload their artifacts 44 // to the local repo. 45 task(mainUpload) << { 46 } 47 48 // repository creation task 49 task createRepository(type: Zip, dependsOn: mainUpload) { 50 from project.ext.supportRepoOut 51 destinationDir project.ext.distDir 52 into 'm2repository' 53 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) 54 } 55 createArchive.dependsOn createRepository 56 57 // prepare repository with older versions 58 task unzipRepo(type: Copy) { 59 from "$rootDir/../../prebuilts/maven_repo/android" 60 into project.ext.supportRepoOut 61 } 62 63 unzipRepo.doFirst { 64 project.ext.supportRepoOut.deleteDir() 65 project.ext.supportRepoOut.mkdirs() 66 } 67 68 // anchor for prepare repo. This is post unzip + sourceProp. 69 task(prepareRepo) << { 70 } 71 72 import com.google.common.io.Files 73 import com.google.common.base.Charsets 74 75 task(createXml) << { 76 def repoArchive = createRepository.archivePath 77 def repoArchiveName = createRepository.archiveName 78 def size = repoArchive.length() 79 def sha1 = getSha1(repoArchive) 80 81 def xml = 82 "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ 83 <sdk:extra>\n\ 84 <sdk:revision>\n\ 85 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ 86 </sdk:revision>\n\ 87 <sdk:vendor-display>Android</sdk:vendor-display>\n\ 88 <sdk:vendor-id>android</sdk:vendor-id>\n\ 89 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ 90 <sdk:path>m2repository</sdk:path>\n\ 91 <sdk:archives>\n\ 92 <sdk:archive>\n\ 93 <sdk:size>${size}</sdk:size>\n\ 94 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ 95 <sdk:url>${repoArchiveName}</sdk:url>\n\ 96 </sdk:archive>\n\ 97 </sdk:archives>\n\ 98 </sdk:extra>\n\ 99 </sdk:sdk-addon>" 100 101 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) 102 } 103 createArchive.dependsOn createXml 104 105 task(createSourceProp) << { 106 def sourceProp = 107 "Extra.VendorDisplay=Android\n\ 108 Extra.Path=m2repository\n\ 109 Archive.Arch=ANY\n\ 110 Extra.NameDisplay=Android Support Repository\n\ 111 Archive.Os=ANY\n\ 112 Pkg.Revision=${project.ext.extraVersion}.0.0\n\ 113 Extra.VendorId=android" 114 115 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) 116 } 117 createSourceProp.dependsOn unzipRepo 118 prepareRepo.dependsOn createSourceProp 119 120 121 import com.google.common.hash.HashCode 122 import com.google.common.hash.HashFunction 123 import com.google.common.hash.Hashing 124 import java.nio.charset.Charset 125 126 def getSha1(File inputFile) { 127 HashFunction hashFunction = Hashing.sha1() 128 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) 129 return hashCode.toString() 130 } 131 132 subprojects { 133 // Change buildDir first so that all plugins pick up the new value. 134 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") 135 136 apply plugin: 'maven' 137 138 version = rootProject.ext.supportVersion 139 group = 'com.android.support' 140 141 repositories { 142 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" } 143 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" } 144 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" } 145 } 146 147 task release(type: Upload) { 148 configuration = configurations.archives 149 repositories { 150 mavenDeployer { 151 repository(url: uri("$rootProject.ext.supportRepoOut")) 152 } 153 } 154 } 155 156 def deployer = release.repositories.mavenDeployer 157 deployer.pom*.whenConfigured { pom -> 158 pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar' 159 } 160 161 // before the upload, make sure the repo is ready. 162 release.dependsOn rootProject.tasks.prepareRepo 163 // make the mainupload depend on this one. 164 mainUpload.dependsOn release 165 166 project.plugins.whenPluginAdded { plugin -> 167 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { 168 project.android.buildToolsVersion = rootProject.buildToolsVersion 169 } 170 } 171 } 172 173 FileCollection getAndroidPrebuilt(String apiLevel) { 174 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar") 175 } 176