huangcm
2024-12-18 9d29be7f7249789d6ffd0440067187a9f040c2cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath libraries.android_tools
    }
}
 
plugins {
    id 'com.github.dcendents.android-maven' version '2.1'
}
 
description = 'Conscrypt: Android'
 
ext {
    androidHome = "$System.env.ANDROID_HOME"
    androidSdkInstalled = file("$androidHome").exists()
    androidVersionCode = 1
    androidVersionName = "$version"
    androidMinSdkVersion = 9
    androidTargetSdkVersion = 26
}
 
if (androidSdkInstalled) {
    apply plugin: 'com.android.library'
    apply plugin: 'com.github.dcendents.android-maven'
 
    // Since we're not taking a direct dependency on the constants module, we need to add an
    // explicit task dependency to make sure the code is generated.
    evaluationDependsOn(':conscrypt-constants')
 
    android {
        compileSdkVersion androidTargetSdkVersion
 
        compileOptions {
            sourceCompatibility androidMinJavaVersion
            targetCompatibility androidMinJavaVersion
        }
 
        defaultConfig {
            minSdkVersion androidMinSdkVersion
            targetSdkVersion androidTargetSdkVersion
            versionCode androidVersionCode
            versionName androidVersionName
 
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 
            consumerProguardFiles 'proguard-rules.pro'
 
            externalNativeBuild {
                cmake {
                    arguments '-DANDROID=True',
                            '-DANDROID_STL=c++_static',
                            "-DBORINGSSL_HOME=$boringsslHome"
                    cFlags '-fvisibility=hidden',
                            '-DBORINGSSL_SHARED_LIBRARY',
                            '-DBORINGSSL_IMPLEMENTATION',
                            '-DOPENSSL_SMALL',
                            '-D_XOPEN_SOURCE=700',
                            '-Wno-unused-parameter'
                }
            }
            ndk {
                abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        sourceSets.main {
            java {
                srcDirs = [
                        "${rootDir}/common/src/main/java",
                        "src/main/java"
                ]
                // Requires evaluationDependsOn(':conscrypt-constants') above.
                srcDirs += project(':conscrypt-constants').sourceSets.main.java.srcDirs
            }
            resources {
                srcDirs += "build/generated/resources"
            }
        }
        externalNativeBuild {
            cmake {
                path 'CMakeLists.txt'
            }
        }
        lintOptions {
            lintConfig file('lint.xml')
        }
    }
 
    configurations {
        publicApiDocs
    }
 
    preBuild {
        dependsOn generateProperties
    }
 
    dependencies {
        publicApiDocs project(':conscrypt-api-doclet')
        androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
            exclude module: 'support-annotations'
            exclude module: 'support-v4'
            exclude module: 'support-v13'
            exclude module: 'recyclerview-v7'
            exclude module: 'appcompat-v7'
            exclude module: 'design'
        })
        compileOnly project(':conscrypt-android-stub')
 
        // Adds the constants module as a dependency so that we can include its generated source
        compileOnly project(':conscrypt-constants')
    }
 
    task configureJavadocs {
        dependsOn configurations.publicApiDocs
        doLast {
            javadocs.options.docletpath = configurations.publicApiDocs.files as List
        }
    }
 
    task javadocs(type: Javadoc, dependsOn: [configureJavadocs]) {
        source = android.sourceSets.main.java.srcDirs
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + project(':conscrypt-android-stub').sourceSets.main.output
        // TODO(nmittler): Fix the javadoc errors.
        failOnError false
        options {
            encoding = 'UTF-8'
            links "https://docs.oracle.com/javase/7/docs/api/"
            doclet = "org.conscrypt.doclet.FilterDoclet"
            // Disable JavaDoc doclint on Java 8. It's annoying.
            if (JavaVersion.current().isJava8Compatible()) {
                addStringOption('Xdoclint:none', '-quiet')
            }
        }
    }
 
    task javadocsJar(type: Jar, dependsOn: javadocs) {
        classifier = 'javadoc'
        from javadocs.destinationDir
    }
 
    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
    }
 
    artifacts {
        archives sourcesJar
        archives javadocsJar
    }
 
    uploadArchives.repositories.mavenDeployer {
        beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
        String stagingUrl
        if (rootProject.hasProperty('repositoryId')) {
            stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
                    rootProject.repositoryId
        } else {
            stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
        }
        def configureAuth = {
            if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
                authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
            }
        }
        repository(url: stagingUrl, configureAuth)
        snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
    }
 
    [
            install.repositories.mavenInstaller,
            uploadArchives.repositories.mavenDeployer,
    ]*.pom*.whenConfigured { pom ->
        pom.project {
            name "$project.group:$project.name"
            description project.description
            url 'https://conscrypt.org/'
 
            scm {
                connection 'scm:git:https://github.com/google/conscrypt.git'
                developerConnection 'scm:git:git@github.com:google/conscrypt.git'
                url 'https://github.com/google/conscrypt'
            }
 
            licenses {
                license {
                    name 'Apache 2'
                    url 'https://www.apache.org/licenses/LICENSE-2.0'
                }
            }
 
            developers {
                developer {
                    id "conscrypt"
                    name "Conscrypt Contributors"
                    email "conscrypt@googlegroups.com"
                    url "https://conscrypt.org/"
                    organization = "Google, Inc."
                    organizationUrl "https://www.google.com"
                }
            }
        }
    }
 
} else {
    logger.warn('Android SDK has not been detected. The Android module will not be built.')
 
    // Disable all tasks
    tasks.collect {
        it.enabled = false
    }
}