build.gradle revision daea069fe33cc750bcb733ebcb6206d2dcedae76
1apply plugin: 'android-library'
2archivesBaseName = 'support-v4'
3
4// create a jar task for the code internal implementation
5tasks.create(name: "internalJar", type: Jar) {
6    baseName "internal_impl"
7}
8
9// --------------------------
10// TO ADD NEW PLATFORM SPECIFIC CODE, UPDATE THIS:
11// create and configure the sourcesets/dependencies for platform-specific code.
12// values are: sourceset name, source folder name, api level, previous sourceset.
13
14ext.allSS = []
15
16def baseSS         = createApiSourceset('donut',         'donut',          '4',       null)
17def eclairSS       = createApiSourceset('eclair',       'eclair',        '5',       baseSS)
18def eclairMr1SS    = createApiSourceset('eclairmr1',    'eclair-mr1',    '7',       eclairSS)
19def froyoSS        = createApiSourceset('froyo',        'froyo',         '8',       eclairMr1SS)
20def gingerbreadSS  = createApiSourceset('gingerbread',  'gingerbread',   '9',       froyoSS)
21def honeycombSS    = createApiSourceset('honeycomb',    'honeycomb',     '11',      gingerbreadSS)
22def honeycombMr1SS = createApiSourceset('honeycombmr1', 'honeycomb_mr1', '12',      honeycombSS)
23def honeycombMr2SS = createApiSourceset('honeycombmr2', 'honeycomb_mr2', '13',      honeycombMr1SS)
24def icsSS          = createApiSourceset('ics',          'ics',           '14',      honeycombMr2SS)
25def icsMr1SS       = createApiSourceset('icsmr1',       'ics-mr1',       '15',      icsSS)
26def jbSS           = createApiSourceset('jellybean',    'jellybean',     '16',      icsMr1SS)
27def jbMr1SS        = createApiSourceset('jellybeanmr1', 'jellybean-mr1', '17',      jbSS)
28def jbMr2SS        = createApiSourceset('jellybeanmr2', 'jellybean-mr2', '18',      jbMr1SS)
29def kitkatSS       = createApiSourceset('kitkat',       'kitkat',        '19',      jbMr2SS)
30def api20SS        = createApiSourceset('api20',        'api20',         '20',      kitkatSS)
31def api21SS        = createApiSourceset('api21',        'api21',         '21',      api20SS)
32def api22SS        = createApiSourceset('api22',        'api22',         '22',      api21SS)
33def api23SS        = createApiSourceset('api23',        'api23',         'current', api22SS)
34
35
36def createApiSourceset(String name, String folder, String apiLevel, SourceSet previousSource) {
37    def sourceSet = sourceSets.create(name)
38    sourceSet.java.srcDirs = [folder]
39
40    def configName = sourceSet.getCompileConfigurationName()
41
42    project.getDependencies().add(configName, getAndroidPrebuilt(apiLevel))
43    if (previousSource != null) {
44        setupDependencies(configName, previousSource)
45    }
46    ext.allSS.add(sourceSet)
47
48    internalJar.from sourceSet.output
49
50    return sourceSet
51}
52
53def setupDependencies(String configName, SourceSet previousSourceSet) {
54    project.getDependencies().add(configName, previousSourceSet.output)
55    project.getDependencies().add(configName, previousSourceSet.compileClasspath)
56}
57
58dependencies {
59    compile project(':support-annotations')
60    donutCompile project(':support-annotations')
61
62    // add the internal implementation as a dependency.
63    // this is not enough to make the regular compileJava task
64    // depend on the generation of this jar. This is done below
65    // when manipulating the libraryVariants.
66    compile files(internalJar.archivePath)
67
68    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
69    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
70    testCompile 'junit:junit:4.12'
71}
72
73android {
74    compileSdkVersion 4
75
76    defaultConfig {
77        minSdkVersion 4
78        // TODO: get target from branch
79        //targetSdkVersion 19
80
81        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
82    }
83
84    sourceSets {
85        main.manifest.srcFile 'AndroidManifest.xml'
86        main.java.srcDirs = ['java']
87        main.aidl.srcDirs = ['java']
88
89        androidTest.setRoot('tests')
90        androidTest.java.srcDir 'tests/java'
91        androidTest.res.srcDir 'tests/res'
92        androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
93    }
94
95    lintOptions {
96        // TODO: fix errors and reenable.
97        abortOnError false
98    }
99
100    compileOptions {
101        sourceCompatibility JavaVersion.VERSION_1_7
102        targetCompatibility JavaVersion.VERSION_1_7
103    }
104
105    testOptions {
106        unitTests.returnDefaultValues = true
107        compileSdkVersion 'current'
108    }
109}
110
111android.libraryVariants.all { variant ->
112    variant.javaCompile.dependsOn internalJar
113
114    def name = variant.buildType.name
115
116    if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
117        return; // Skip debug builds.
118    }
119    def suffix = name.capitalize()
120
121    def jarTask = project.tasks.create(name: "jar${suffix}", type: Jar){
122        dependsOn variant.javaCompile
123        from variant.javaCompile.destinationDir
124        from 'LICENSE.txt'
125    }
126    def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
127        source android.sourceSets.main.java
128        classpath = files(variant.javaCompile.classpath.files) + files(
129                "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
130    }
131
132    def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
133        classifier = 'javadoc'
134        from 'build/docs/javadoc'
135    }
136
137    def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
138        classifier = 'sources'
139        from android.sourceSets.main.java.srcDirs
140        exclude('android/content/pm/**')
141        exclude('android/service/media/**')
142    }
143
144    project.ext.allSS.each { ss ->
145        javadocTask.source ss.java
146        sourcesJarTask.from ss.java.srcDirs
147    }
148
149    artifacts.add('archives', javadocJarTask);
150    artifacts.add('archives', sourcesJarTask);
151}
152
153uploadArchives {
154    repositories {
155        mavenDeployer {
156            repository(url: uri(rootProject.ext.supportRepoOut)) {
157            }
158
159            pom.project {
160                name 'Android Support Library v4'
161                description "The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 4 or later."
162                url 'http://developer.android.com/tools/extras/support-library.html'
163                inceptionYear '2011'
164
165                licenses {
166                    license {
167                        name 'The Apache Software License, Version 2.0'
168                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
169                        distribution 'repo'
170                    }
171                }
172
173                scm {
174                    url "http://source.android.com"
175                    connection "scm:git:https://android.googlesource.com/platform/frameworks/support"
176                }
177                developers {
178                    developer {
179                        name 'The Android Open Source Project'
180                    }
181                }
182            }
183        }
184    }
185}
186