• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1buildscript {
2    repositories {
3        google()
4        jcenter()
5    }
6    dependencies {
7        classpath libraries.android_tools
8    }
9}
10
11plugins {
12    id 'digital.wup.android-maven-publish' version '3.6.2'
13}
14
15description = 'Conscrypt: Android'
16
17ext {
18    androidHome = "$System.env.ANDROID_HOME"
19    androidSdkInstalled = file("$androidHome").exists()
20    androidVersionCode = 1
21    androidVersionName = "$version"
22    androidMinSdkVersion = 9
23    androidTargetSdkVersion = 26
24    androidNdkVersion = "21.3.6528147"
25}
26
27if (androidSdkInstalled) {
28    apply plugin: 'com.android.library'
29
30    // Since we're not taking a direct dependency on the constants module, we need to add an
31    // explicit task dependency to make sure the code is generated.
32    evaluationDependsOn(':conscrypt-constants')
33
34    android {
35        compileSdkVersion androidTargetSdkVersion
36        ndkVersion androidNdkVersion
37
38        compileOptions {
39            sourceCompatibility androidMinJavaVersion
40            targetCompatibility androidMinJavaVersion
41        }
42
43        defaultConfig {
44            minSdkVersion androidMinSdkVersion
45            targetSdkVersion androidTargetSdkVersion
46            versionCode androidVersionCode
47            versionName androidVersionName
48
49            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
50
51            consumerProguardFiles 'proguard-rules.pro'
52
53            externalNativeBuild {
54                cmake {
55                    arguments '-DANDROID=True',
56                            '-DANDROID_STL=c++_static',
57                            "-DBORINGSSL_HOME=$boringsslHome"
58                    cFlags '-fvisibility=hidden',
59                            '-DBORINGSSL_SHARED_LIBRARY',
60                            '-DBORINGSSL_IMPLEMENTATION',
61                            '-DOPENSSL_SMALL',
62                            '-D_XOPEN_SOURCE=700',
63                            '-Wno-unused-parameter'
64                    targets 'conscrypt_jni'
65                }
66            }
67            ndk {
68                abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
69            }
70        }
71        buildTypes {
72            release {
73                minifyEnabled false
74                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
75            }
76        }
77        sourceSets.main {
78            java {
79                srcDirs = [
80                        "${rootDir}/common/src/main/java",
81                        "src/main/java"
82                ]
83                // Requires evaluationDependsOn(':conscrypt-constants') above.
84                srcDirs += project(':conscrypt-constants').sourceSets.main.java.srcDirs
85            }
86            resources {
87                srcDirs += "build/generated/resources"
88            }
89        }
90        externalNativeBuild {
91            cmake {
92                path 'CMakeLists.txt'
93            }
94        }
95        lintOptions {
96            lintConfig file('lint.xml')
97        }
98    }
99
100    configurations {
101        publicApiDocs
102    }
103
104    preBuild {
105        dependsOn generateProperties
106    }
107
108    dependencies {
109        publicApiDocs project(':conscrypt-api-doclet')
110        androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
111            exclude module: 'support-annotations'
112            exclude module: 'support-v4'
113            exclude module: 'support-v13'
114            exclude module: 'recyclerview-v7'
115            exclude module: 'appcompat-v7'
116            exclude module: 'design'
117        })
118        compileOnly project(':conscrypt-android-stub')
119
120        // Adds the constants module as a dependency so that we can include its generated source
121        compileOnly project(':conscrypt-constants')
122    }
123
124    def configureJavaDocs = tasks.register("configureJavadocs") {
125        dependsOn configurations.publicApiDocs
126        doLast {
127            javadocs.options.docletpath = configurations.publicApiDocs.files as List
128        }
129    }
130
131    def javadocs = tasks.register("javadocs", Javadoc) {
132        dependsOn configureJavadocs
133        source = android.sourceSets.main.java.srcDirs
134        classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + project(':conscrypt-android-stub').sourceSets.main.output
135        // TODO(nmittler): Fix the javadoc errors.
136        failOnError false
137        options {
138            encoding = 'UTF-8'
139            links "https://docs.oracle.com/javase/7/docs/api/"
140            doclet = "org.conscrypt.doclet.FilterDoclet"
141            // Disable JavaDoc doclint on Java 8. It's annoying.
142            if (JavaVersion.current().isJava8Compatible()) {
143                addStringOption('Xdoclint:none', '-quiet')
144            }
145        }
146    }
147
148    def javadocsJar = tasks.register("javadocsJar", Jar) {
149        dependsOn javadocs
150        classifier = 'javadoc'
151        from {
152            javadocs.get().destinationDir
153        }
154    }
155
156    def sourcesJar = tasks.register("sourcesJar", Jar) {
157        classifier = 'sources'
158        from android.sourceSets.main.java.srcDirs
159    }
160
161    apply from: "$rootDir/gradle/publishing.gradle"
162    publishing.publications.maven {
163        from components.android
164        artifact sourcesJar.get()
165        artifact javadocsJar.get()
166    }
167} else {
168    logger.warn('Android SDK has not been detected. The Android module will not be built.')
169
170    // Disable all tasks
171    tasks.configureEach {
172        it.enabled = false
173    }
174}
175