普通文本  |  111行  |  3.78 KB

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.gradle.internal.os.OperatingSystem

buildscript {
    repositories {
        maven { url '../../prebuilts/gradle-plugin' }
        maven { url '../../prebuilts/tools/common/m2/repository' }
        maven { url '../../prebuilts/tools/common/m2/internal' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

apply from: 'version.gradle'

final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
System.setProperty('android.dir', "${rootDir}/../../")
final String fullSdkPath = "${rootDir}/../../prebuilts/fullsdk-${platform}"
if (file(fullSdkPath).exists()) {
    gradle.ext.currentSdk = 26
    ext.buildToolsVersion = '26.0.0'
    project.ext.androidJar = files("${fullSdkPath}/platforms/android-${gradle.currentSdk}/android.jar")
    System.setProperty('android.home', "${rootDir}/../../prebuilts/fullsdk-${platform}")
    File props = file("local.properties")
    props.write "sdk.dir=${fullSdkPath}"
} else {
    gradle.ext.currentSdk = 'current'
    ext.buildToolsVersion = '26.0.0'
    project.ext.androidJar = files("${project.rootDir}/../../prebuilts/sdk/current/android.jar")
    File props = file("local.properties")
    props.write "android.dir=../../"
}

/*
 * With the build server you are given two env variables.
 * The OUT_DIR is a temporary directory you can use to put things during the build.
 * The DIST_DIR is where you want to save things from the build.
 *
 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
 */
if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
    buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
    project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
} else {
    buildDir = file('../../out/host/gradle/frameworks/support/build')
    project.ext.distDir = file('../../out/dist')
}

ext.supportRepoOut = new File(buildDir, 'support_repo')

// upload anchor for subprojects to upload their artifacts
// to the local repo.
task(dist) {
    group = BasePlugin.BUILD_GROUP
    description 'Builds distribution artifacts.'
}

subprojects {
    // Change buildDir first so that all plugins pick up the new value.
    project.buildDir = project.file("${project.parent.buildDir}/../${project.name}/build")

    apply plugin: 'maven'

    version = rootProject.multidexVersion
    group = 'com.android.support'

    task release(type: Upload) {
        configuration = configurations.archives
        repositories {
            mavenDeployer {
                repository(url: uri("$rootProject.supportRepoOut"))
            }
        }
    }

    task createArtifactZip(type: Zip, dependsOn: release)  {
        from release.artifacts
        into archivesBaseName
        destinationDir project.parent.distDir
        baseName = archivesBaseName

        doLast {
            logger.warn "Compressed maven artifacts to ${archivePath}"
        }
    }

    dist.dependsOn createArtifactZip

    project.plugins.whenPluginAdded { plugin ->
        if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
            project.android.buildToolsVersion = rootProject.buildToolsVersion
        }
    }
}