-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbuild.gradle
More file actions
256 lines (227 loc) · 8.91 KB
/
Copy pathbuild.gradle
File metadata and controls
256 lines (227 loc) · 8.91 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
apply plugin: 'com.android.library'
apply plugin: "maven-publish"
apply plugin: "signing"
apply plugin: "com.google.devtools.ksp"
import org.gradle.internal.logging.text.StyledTextOutputFactory
import static org.gradle.internal.logging.text.StyledTextOutput.Style
import java.nio.file.Files
import java.nio.file.Paths
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
def log = services.get(StyledTextOutputFactory).create("sqlcipher")
android {
compileSdkVersion 37
namespace "net.zetetic.database"
defaultConfig {
minSdkVersion "${rootProject.ext.minSdkVersion}"
targetSdkVersion 37
versionCode 1
versionName "${rootProject.ext.libraryVersion}"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
consumerProguardFiles 'consumer-rules.pro'
}
base {
archivesName = "sqlcipher-android-${rootProject.ext.libraryVersion}"
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
buildTypes {
release {
minifyEnabled false
}
releaseNoX86 {
minifyEnabled false
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
}
}
debug {
minifyEnabled false
debuggable true
jniDebuggable true
ndk {
// Building with NDK_DEBUG=1 for mips crashes the compiler in ndk 14.
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
//sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
ndkVersion "${rootProject.ext.androidNdkVersion}"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
}
}
static def shellCmd(String workingDirectory,
String... arguments) {
if (!arguments || arguments.length == 0) {
throw new IllegalArgumentException("At least one argument is required")
}
def command = ["sh", "-c", 'exec "$@"', "sh", *arguments]
def processBuilder = new ProcessBuilder(command)
processBuilder.directory(new File(workingDirectory))
def process = processBuilder.start()
process.inputStream.eachLine { println it }
process.errorStream.eachLine { System.err.println(it) }
process.waitFor()
}
def generateAmalgamation = tasks.register("generateAmalgamation") {
description = "Generate SQLCipher amalgamation source files"
group = "SQLCipher"
def sqlcipherDir = new File("${project.rootDir}/sqlcipher/src/main/jni/sqlcipher/")
def sqlcipherSourceDir = new File(sqlcipherDir.absolutePath, "src/")
def sqlcipherReadMe = new File(sqlcipherSourceDir.absolutePath, "README.md")
def amalgamationSource = new File(sqlcipherDir.absolutePath, "sqlite3.c")
def amalgamationHeader = new File(sqlcipherDir.absolutePath, "sqlite3.h")
doLast {
if(!sqlcipherReadMe.exists()) {
log.withStyle(Style.Info).println('SQLCipher README missing, initializing submodule')
shellCmd(project.rootDir.absolutePath, "git", "submodule", "update", "--init")
}
log.withStyle(Style.Info).println('SQLCipher amalgamation not found, generating.')
shellCmd(sqlcipherSourceDir.absolutePath, "./configure", "--with-tempstore=yes", "--disable-tcl")
shellCmd(sqlcipherSourceDir.absolutePath, "make", "clean")
shellCmd(sqlcipherSourceDir.absolutePath, "make", "sqlite3.c")
def filesToMove = ["sqlite3.c", "sqlite3.h"]
filesToMove.each {
def sourcePath = Paths.get(sqlcipherSourceDir.absolutePath, it)
def targetPath = Paths.get(sqlcipherDir.absolutePath, it)
def moveResult = Files.move(sourcePath, targetPath, REPLACE_EXISTING)
if(moveResult == null){
throw new GradleException("Faile to move ${sourcePath} to ${targetPath}")
}
}
}
onlyIf {
return !(amalgamationSource.exists()
&& amalgamationHeader.exists())
}
}
tasks.matching { it.name == "preBuild" }.configureEach {
dependsOn generateAmalgamation
}
def cleanAmalgamation = tasks.register("cleanAmalgamation") {
description = "Cleans SQLCipher amalgamation source files"
group = "SQLCipher"
def amalgamationSource = file("${project.rootDir}/sqlcipher/src/main/jni/sqlcipher/sqlite3.c")
def amalgamationHeader = file("${project.rootDir}/sqlcipher/src/main/jni/sqlcipher/sqlite3.h")
doLast {
println "Clean SQLCipher amalgamation"
delete(amalgamationSource, amalgamationHeader)
}
onlyIf {
return amalgamationSource.exists()
|| amalgamationHeader.exists()
}
}
tasks.named("clean") {
dependsOn(cleanAmalgamation)
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Needed for the Support API interfaces
implementation "androidx.sqlite:sqlite:${rootProject.ext.androidXSQLiteVersion}"
// Needed for the Room library in tests
def room_version = "3.0.1"
androidTestImplementation "androidx.room3:room3-runtime:$room_version"
kspAndroidTest "androidx.room3:room3-compiler:$room_version"
// Needed for roomDatabase.getSupportWrapper() tests
androidTestImplementation "androidx.room3:room3-sqlite-wrapper:$room_version"
// Needed for runTest
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0"
// Needed for supporting tests
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test:rules:1.7.0'
androidTestImplementation 'androidx.test:core:1.7.0'
androidTestImplementation 'org.hamcrest:hamcrest-library:3.0'
testImplementation 'junit:junit:4.13.2'
androidTestUtil 'androidx.test:orchestrator:1.6.1'
}
allprojects {
repositories {
// The order in which you list these repositories matter.
google()
}
}
static def getReleaseRepositoryUrl() {
return "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
}
def getRepositoryUsername() {
return hasProperty('nexusUsername') ? nexusUsername : ""
}
def getRepositoryPassword() {
return hasProperty('nexusPassword') ? nexusPassword : ""
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { it instanceof Sign }) {
allprojects { ext."signing.keyId" = "${signingKeyId}" }
allprojects { ext."signing.secretKeyRingFile" = "${signingKeyRingFile}" }
allprojects { ext."signing.password" = "${signingKeyPassword}" }
}
}
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
groupId = "net.zetetic"
artifactId = "sqlcipher-android"
version = "${rootProject.ext.mavenVersionName}"
from components.release
pom {
name = "sqlcipher-android"
packaging = "aar"
description = "SQLCipher for Android a library that provides full database encryption."
url = "https://www.zetetic.net/sqlcipher"
scm {
url = "https://github.com/sqlcipher/sqlcipher-android.git"
connection = "scm:git:https://github.com/sqlcipher/sqlcipher-android.git"
developerConnection = "scm:git:https://github.com/sqlcipher/sqlcipher-android.git"
}
licenses {
license {
url = "https://www.zetetic.net/sqlcipher/license/"
}
}
developers {
developer {
name = "Zetetic Support"
email = "support@zetetic.net"
organization = "Zetetic LLC"
organizationUrl = "https://www.zetetic.net"
}
}
}
}
}
repositories {
maven {
def repoUrl = getReleaseRepositoryUrl()
url = repoUrl
credentials {
username = getRepositoryUsername()
password = getRepositoryPassword()
}
}
}
}
signing {
required { gradle.taskGraph.hasTask("publish") }
sign publishing.publications.mavenJava
}
}