Skip to content

Commit 28a9ff8

Browse files
Support building SQLCipher with LTC by default within project
1 parent 35ccc4c commit 28a9ff8

5 files changed

Lines changed: 640 additions & 25 deletions

File tree

Makefile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ build-release:
1919
-PsqlcipherAndroidVersion="$(SQLCIPHER_ANDROID_VERSION)" \
2020
assembleRelease
2121

22-
publish-snapshot-to-local-maven:
23-
@ $(collect-signing-info) \
24-
$(GRADLE) \
25-
-PpublishSnapshot=true \
26-
-Psigning.keyId="$$gpgKeyId" \
27-
-Psigning.secretKeyRingFile="$$gpgKeyRingFile" \
28-
-Psigning.password="$$gpgPassword" \
29-
publishReleasePublicationToMavenLocal
30-
3122
publish-remote-release:
3223
@ $(collect-signing-info) \
3324
$(collect-nexus-info) \

build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ project.ext {
3333
if(project.hasProperty('sqlcipherAndroidVersion') && "${sqlcipherAndroidVersion}") {
3434
libraryVersion = "${sqlcipherAndroidVersion}"
3535
} else {
36-
libraryVersion = "undefined"
36+
libraryVersion = "4.14.0"
3737
}
3838
minSdkVersion = 21
3939
androidXSQLiteVersion = "2.2.0"
@@ -64,20 +64,20 @@ project.ext {
6464
nexusStagingProfileId = project.hasProperty('nexusStagingProfileId') ? "${nexusStagingProfileId}" : ""
6565
}
6666

67-
task generateReadMe {
67+
def generateReadMe = tasks.register('generateReadMe') {
6868
def readme = new File("README.md")
6969
def engine = new SimpleTemplateEngine()
7070
def reader = new FileReader("README.md.template")
7171
def binding = [
72-
libraryVersion: project.ext.libraryVersion,
73-
androidXSQLiteVersion: project.ext.androidXSQLiteVersion,
74-
androidNdkVersion: project.ext.androidNdkVersion,
75-
minSdkVersion: project.ext.minSdkVersion,
76-
]
72+
libraryVersion : project.ext.libraryVersion,
73+
androidXSQLiteVersion: project.ext.androidXSQLiteVersion,
74+
androidNdkVersion : project.ext.androidNdkVersion,
75+
minSdkVersion : project.ext.minSdkVersion,
76+
]
7777
def template = engine.createTemplate(reader).make(binding)
7878
readme.write(template.toString())
7979
}
8080

8181
project.afterEvaluate {
82-
build.dependsOn generateReadMe
82+
build.dependsOn(generateReadMe)
8383
}

sqlcipher/build.gradle

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ apply plugin: 'com.android.library'
22
apply plugin: "maven-publish"
33
apply plugin: "signing"
44

5+
import org.gradle.internal.logging.text.StyledTextOutputFactory;
6+
import static org.gradle.internal.logging.text.StyledTextOutput.Style;
7+
import java.nio.file.Files
8+
import java.nio.file.Paths
9+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
10+
11+
def log = services.get(StyledTextOutputFactory).create("sqlcipher")
12+
513
android {
614
compileSdkVersion 34
715
namespace "net.zetetic.database"
@@ -69,6 +77,75 @@ android {
6977

7078
}
7179

80+
static def shellCmd(String workingDirectory,
81+
String... arguments) {
82+
if (!arguments || arguments.length == 0) {
83+
throw new IllegalArgumentException("At least one argument is required")
84+
}
85+
def command = ["sh", "-c", 'exec "$@"', "sh", *arguments]
86+
def processBuilder = new ProcessBuilder(command)
87+
processBuilder.directory(new File(workingDirectory))
88+
def process = processBuilder.start()
89+
process.inputStream.eachLine { println it }
90+
process.errorStream.eachLine { System.err.println(it) }
91+
process.waitFor()
92+
}
93+
94+
def generateAmalgamation = tasks.register("generateAmalgamation") {
95+
description = "Generate SQLCipher amalgamation source files"
96+
group = "SQLCipher"
97+
def sqlcipherDir = new File("${project.rootDir}/sqlcipher/src/main/jni/sqlcipher/")
98+
def submoduleDir = new File(sqlcipherDir.absolutePath, "src/")
99+
def amalgamationSource = new File(sqlcipherDir.absolutePath, "sqlite3.c")
100+
def amalgamationHeader = new File(sqlcipherDir.absolutePath, "sqlite3.h")
101+
doLast {
102+
if(!submoduleDir.exists()) {
103+
log.withStyle(Style.Failure).println('SQLCipher submodule missing, exiting')
104+
throw new GradleException("SQLCipher submodule missing: please run git submodule update --init")
105+
}
106+
log.withStyle(Style.Info).println('SQLCipher amalgamation not found, generating.')
107+
shellCmd(submoduleDir.absolutePath, "./configure", "--with-tempstore=yes", "--disable-tcl")
108+
shellCmd(submoduleDir.absolutePath, "make", "clean")
109+
shellCmd(submoduleDir.absolutePath, "make", "sqlite3.c")
110+
def filesToMove = ["sqlite3.c", "sqlite3.h"]
111+
filesToMove.each {
112+
def sourcePath = Paths.get(submoduleDir.absolutePath, it)
113+
def targetPath = Paths.get(sqlcipherDir.absolutePath, it)
114+
def moveResult = Files.move(sourcePath, targetPath, REPLACE_EXISTING);
115+
if(moveResult == null){
116+
throw new GradleException("Faile to move ${sourcePath} to ${targetPath}")
117+
}
118+
}
119+
}
120+
outputs.upToDateWhen {
121+
return amalgamationSource.exists()
122+
&& amalgamationHeader.exists()
123+
}
124+
}
125+
126+
tasks.matching { it.name == "preBuild" }.configureEach {
127+
dependsOn generateAmalgamation
128+
}
129+
130+
def cleanAmalgamation = tasks.register("cleanAmalgamation") {
131+
description = "Cleans SQLCipher amalgamation source files"
132+
group = "SQLCipher"
133+
def amalgamationSource = file("${project.rootDir}/sqlcipher/src/main/jni/sqlcipher/sqlite3.c")
134+
def amalgamationHeader = file("${project.rootDir}/sqlcipher/src/main/jni/sqlcipher/sqlite3.h")
135+
doLast {
136+
println "Clean SQLCipher amalgamation"
137+
delete(amalgamationSource, amalgamationHeader)
138+
}
139+
outputs.upToDateWhen {
140+
return !amalgamationSource.exists()
141+
&& !amalgamationHeader.exists()
142+
}
143+
}
144+
145+
tasks.named("clean") {
146+
dependsOn(cleanAmalgamation)
147+
}
148+
72149
dependencies {
73150
implementation fileTree(include: ['*.jar'], dir: 'libs')
74151

0 commit comments

Comments
 (0)