Skip to content

Commit 1e8f0f8

Browse files
Externalize SQLCipher/OpenSSL sourcing for build
1 parent 0a0a403 commit 1e8f0f8

File tree

9 files changed

+93
-73
lines changed

9 files changed

+93
-73
lines changed

Diff for: .gitmodules

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
[submodule "android-database-sqlcipher/src/main/external/sqlcipher"]
2-
path = android-database-sqlcipher/src/main/external/sqlcipher
3-
url = https://github.com/sqlcipher/sqlcipher.git
4-
ignore = untracked

Diff for: Makefile

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
publish-local-release publish-remote-snapshot public-remote-release check
44
GRADLE = ./gradlew
55

6-
init:
7-
git submodule update --init
8-
96
clean:
107
$(GRADLE) clean
118

@@ -25,9 +22,14 @@ build-debug: check
2522
$(GRADLE) android-database-sqlcipher:bundleDebugAar \
2623
-PdebugBuild=true
2724

28-
build-release: check
25+
build-release:
2926
$(GRADLE) android-database-sqlcipher:bundleReleaseAar \
30-
-PdebugBuild=false
27+
-PdebugBuild=false \
28+
-PsqlcipherRoot="$(SQLCIPHER_ROOT)" \
29+
-PopensslRoot="$(OPENSSL_ROOT)" \
30+
-PopensslAndroidLibRoot="$(OPENSSL_ANDROID_LIB_ROOT)" \
31+
-PsqlcipherCFlags="$(SQLCIPHER_CFLAGS)" \
32+
-PsqlcipherAndroidClientVersion="$(SQLCIPHER_ANDROID_VERSION)"
3133

3234
publish-local-snapshot:
3335
@ $(collect-signing-info) \
@@ -74,6 +76,11 @@ publish-remote-release:
7476
-PsigningKeyPassword="$$gpgPassword" \
7577
-PnexusUsername="$$nexusUsername" \
7678
-PnexusPassword="$$nexusPassword" \
79+
-PsqlcipherRoot="$(SQLCIPHER_ROOT)" \
80+
-PopensslRoot="$(OPENSSL_ROOT)" \
81+
-PopensslAndroidLibRoot="$(OPENSSL_ANDROID_LIB_ROOT)" \
82+
-PsqlcipherCFlags="$(SQLCIPHER_CFLAGS)" \
83+
-PsqlcipherAndroidClientVersion="$(SQLCIPHER_ANDROID_VERSION)"
7784
uploadArchives
7885

7986
collect-nexus-info := \

Diff for: README.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,9 @@ For applications which utilize ProGuard, a few additional rules must be included
140140
In order to build `android-database-sqlcipher` from source you will need both the Android SDK, Gradle, and the Android NDK. We currently recommend using Android NDK version `r20`. To complete the `make` command, the `ANDROID_NDK_HOME` environment variable must be defined which should point to your NDK root. Once you have cloned the repo, change directory into the root of the repository and run the following commands:
141141

142142
```
143-
# this only needs to be done once
144-
make init
145-
146-
# to build the source for debug:
147-
make build-debug
148-
# or for a release build:
143+
SQLCIPHER_ROOT=/some/path/to/sqlcipher-folder \
144+
OPENSSL_ROOT=/some/path/to/openssl-folder \
145+
SQLCIPHER_ANDROID_VERSION="4.4.1" \
149146
make build-release
150147
```
151148

Diff for: android-database-sqlcipher/build-openssl-libraries.sh

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
MINIMUM_ANDROID_SDK_VERSION=$1
44
MINIMUM_ANDROID_64_BIT_SDK_VERSION=$2
5-
OPENSSL=openssl-$3
5+
OPENSSL_DIR=$3
6+
ANDROID_LIB_ROOT=$4
67

7-
(cd src/main/external/;
8-
gunzip -c ${OPENSSL}.tar.gz | tar xf -
9-
)
10-
11-
(cd src/main/external/${OPENSSL};
8+
(cd ${OPENSSL_DIR};
129

1310
if [[ ! ${MINIMUM_ANDROID_SDK_VERSION} ]]; then
1411
echo "MINIMUM_ANDROID_SDK_VERSION was not provided, include and rerun"
@@ -45,7 +42,6 @@ OPENSSL=openssl-$3
4542
esac
4643

4744
NDK_TOOLCHAIN_VERSION=4.9
48-
ANDROID_LIB_ROOT=../android-libs
4945
OPENSSL_CONFIGURE_OPTIONS="-fPIC -fstack-protector-all no-idea no-camellia \
5046
no-seed no-bf no-cast no-rc2 no-rc4 no-rc5 no-md2 \
5147
no-md4 no-ecdh no-sock no-ssl3 \

Diff for: android-database-sqlcipher/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ android {
5151
check.dependsOn editorconfigCheck
5252
buildNative.mustRunAfter buildAmalgamation
5353
buildAmalgamation.mustRunAfter buildOpenSSL
54-
preBuild.dependsOn([buildOpenSSL, buildAmalgamation, buildNative])
54+
preBuild.dependsOn([buildOpenSSL, buildAmalgamation, copyAmalgamation, buildNative])
55+
buildNative.mustRunAfter(copyAmalgamation)
5556
}

Diff for: android-database-sqlcipher/native.gradle

+32-24
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,40 @@ task buildOpenSSL() {
1616
commandLine "./build-openssl-libraries.sh",
1717
"${minimumAndroidSdkVersion}",
1818
"${minimumAndroid64BitSdkVersion}",
19-
"${opensslVersion}"
19+
"${opensslDir}",
20+
"${androidNativeRootDir}"
2021
}
2122
}
2223
}
2324

2425
task buildAmalgamation() {
2526
onlyIf {
26-
def amalgamation = new File("${projectDir}/src/main/cpp/sqlite3.c")
27+
def amalgamation = new File("${sqlcipherDir}/sqlite3.c")
2728
return !amalgamation.exists()
2829
}
2930
doLast {
3031
exec {
31-
workingDir "${projectDir}/src/main/external/sqlcipher"
32+
workingDir "${sqlcipherDir}"
3233
environment("CFLAGS", "${sqlcipherCFlags}")
3334
commandLine "./configure", "--enable-tempstore=yes", "--with-crypto-lib=none"
3435
}
3536
exec {
36-
workingDir "${projectDir}/src/main/external/sqlcipher"
37+
workingDir "${sqlcipherDir}"
3738
environment("CFLAGS", "${sqlcipherCFlags}")
3839
commandLine "make", "sqlite3.c"
3940
}
40-
exec {
41-
workingDir "${projectDir}/src/main/external/sqlcipher"
42-
commandLine "cp", "sqlite3.c", "sqlite3.h", "${nativeRootOutputDir}/cpp/"
43-
}
4441
}
4542
}
4643

44+
task copyAmalgamation() {
45+
doLast {
46+
exec {
47+
workingDir "${sqlcipherDir}"
48+
commandLine "cp", "sqlite3.c", "sqlite3.h", "${nativeRootOutputDir}/cpp/"
49+
}
50+
}
51+
}
52+
4753
task buildNative() {
4854
description "Build the native SQLCipher binaries"
4955
doLast {
@@ -76,25 +82,27 @@ task cleanOpenSSL() {
7682
description "Clean the OpenSSL source"
7783
doLast {
7884
logger.info "Cleaning OpenSSL source"
79-
File file = new File("${opensslDir}")
80-
if (file.exists()) {
81-
file.deleteDir()
85+
exec {
86+
workingDir "${opensslDir}"
87+
ignoreExitValue true
88+
commandLine "make", "clean"
8289
}
8390
}
8491
}
8592

8693
task cleanSQLCipher() {
87-
description "Clean the SQLCipher source"
88-
gitClean("${sqlcipherDir}")
89-
exec {
90-
workingDir "${sqlcipherDir}"
91-
ignoreExitValue true
92-
commandLine "make", "clean"
93-
}
94-
File amalgamationDestinationSource = new File("${nativeRootOutputDir}/cpp/sqlite3.c")
95-
File amalgamationDestinationHeader = new File("${nativeRootOutputDir}/cpp/sqlite3.h")
96-
if (amalgamationDestinationSource.exists()) amalgamationDestinationSource.delete()
97-
if (amalgamationDestinationHeader.exists()) amalgamationDestinationHeader.delete()
94+
description "Clean the SQLCipher source"
95+
doLast {
96+
exec {
97+
workingDir "${sqlcipherDir}"
98+
ignoreExitValue true
99+
commandLine "make", "clean"
100+
}
101+
File amalgamationDestinationSource = new File("${nativeRootOutputDir}/cpp/sqlite3.c")
102+
File amalgamationDestinationHeader = new File("${nativeRootOutputDir}/cpp/sqlite3.h")
103+
if (amalgamationDestinationSource.exists()) amalgamationDestinationSource.delete()
104+
if (amalgamationDestinationHeader.exists()) amalgamationDestinationHeader.delete()
105+
}
98106
}
99107

100108
task cleanNative() {
@@ -110,8 +118,9 @@ task cleanNative() {
110118
}
111119
}
112120

113-
task distclean(dependsOn: [clean, cleanSQLCipher, cleanOpenSSL]) {
121+
task distclean() {
114122
description "Clean build, SQLCipher, and OpenSSL artifacts"
123+
dependsOn clean, cleanSQLCipher, cleanOpenSSL
115124
doLast {
116125
new File("${androidNativeRootDir}/").deleteDir()
117126
}
@@ -132,7 +141,6 @@ def gitClean(directory) {
132141
def executeNdkBuild(outputDir, androidMkDirectory, applicationMkFile,
133142
cflags, otherSqlcipherCFlags, androidVersion) {
134143
logger.info "Executing NDK build command"
135-
136144
def out = services.get(StyledTextOutputFactory).create("")
137145
out.style(Style.Normal).text("SQLCIPHER_CFLAGS=").style(Style.Info).println("${cflags}")
138146
out.style(Style.Normal).text("OPENSSL_DIR=").style(Style.Info).println("${opensslDir}")
Binary file not shown.
-1
This file was deleted.

Diff for: build.gradle

+41-25
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ allprojects {
2020
}
2121

2222
ext {
23-
clientVersionNumber = "4.4.0"
23+
if(project.hasProperty('sqlcipherAndroidClientVersion')) {
24+
clientVersionNumber = "${sqlcipherAndroidClientVersion}"
25+
} else {
26+
clientVersionNumber = "UndefinedBuildNumber"
27+
}
2428
mavenPackaging = "aar"
2529
mavenGroup = "net.zetetic"
2630
mavenArtifactId = "android-database-sqlcipher"
@@ -60,38 +64,50 @@ ext {
6064
compileAndroidSdkVersion = 26
6165
mainProjectName = "android-database-sqlcipher"
6266
nativeRootOutputDir = "${projectDir}/${mainProjectName}/src/main"
63-
androidNativeRootDir = "${nativeRootOutputDir}/external/android-libs"
64-
sqlcipherDir = "${projectDir}/${mainProjectName}/src/main/external/sqlcipher"
6567
opensslVersion = "1.1.1g"
66-
opensslDir = "${projectDir}/${mainProjectName}/src/main/external/openssl-${opensslVersion}"
68+
if(project.hasProperty('sqlcipherRoot')) {
69+
sqlcipherDir = "${sqlcipherRoot}"
70+
}
71+
if(project.hasProperty('opensslAndroidLibRoot')) {
72+
androidNativeRootDir = "${opensslAndroidLibRoot}"
73+
} else {
74+
androidNativeRootDir = "${nativeRootOutputDir}/external/android-libs"
75+
}
76+
if(project.hasProperty('opensslRoot')) {
77+
opensslDir = "${opensslRoot}"
78+
}
6779
if(project.hasProperty('debugBuild') && debugBuild.toBoolean()) {
6880
otherSqlcipherCFlags = "-fstack-protector-all"
6981
ndkBuildType="NDK_DEBUG=1"
7082
} else {
7183
otherSqlcipherCFlags = "-DLOG_NDEBUG -fstack-protector-all"
7284
ndkBuildType="NDK_DEBUG=0"
7385
}
74-
sqlcipherCFlags = "-DSQLITE_HAS_CODEC " +
75-
"-DSQLITE_SOUNDEX " +
76-
"-DHAVE_USLEEP=1 " +
77-
"-DSQLITE_MAX_VARIABLE_NUMBER=99999 " +
78-
"-DSQLITE_TEMP_STORE=3 " +
79-
"-DSQLITE_THREADSAFE=1 " +
80-
"-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 " +
81-
"-DNDEBUG=1 " +
82-
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 " +
83-
"-DSQLITE_ENABLE_LOAD_EXTENSION " +
84-
"-DSQLITE_ENABLE_COLUMN_METADATA " +
85-
"-DSQLITE_ENABLE_UNLOCK_NOTIFY " +
86-
"-DSQLITE_ENABLE_RTREE " +
87-
"-DSQLITE_ENABLE_STAT3 " +
88-
"-DSQLITE_ENABLE_STAT4 " +
89-
"-DSQLITE_ENABLE_JSON1 " +
90-
"-DSQLITE_ENABLE_FTS3_PARENTHESIS " +
91-
"-DSQLITE_ENABLE_FTS4 " +
92-
"-DSQLITE_ENABLE_FTS5 " +
93-
"-DSQLCIPHER_CRYPTO_OPENSSL " +
94-
"-DSQLITE_ENABLE_DBSTAT_VTAB"
86+
if(project.hasProperty('sqlcipherCFlags')) {
87+
sqlcipherCFlags = "${sqlcipherCFlags}"
88+
} else {
89+
sqlcipherCFlags = "-DSQLITE_HAS_CODEC " +
90+
"-DSQLITE_SOUNDEX " +
91+
"-DHAVE_USLEEP=1 " +
92+
"-DSQLITE_MAX_VARIABLE_NUMBER=99999 " +
93+
"-DSQLITE_TEMP_STORE=3 " +
94+
"-DSQLITE_THREADSAFE=1 " +
95+
"-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 " +
96+
"-DNDEBUG=1 " +
97+
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 " +
98+
"-DSQLITE_ENABLE_LOAD_EXTENSION " +
99+
"-DSQLITE_ENABLE_COLUMN_METADATA " +
100+
"-DSQLITE_ENABLE_UNLOCK_NOTIFY " +
101+
"-DSQLITE_ENABLE_RTREE " +
102+
"-DSQLITE_ENABLE_STAT3 " +
103+
"-DSQLITE_ENABLE_STAT4 " +
104+
"-DSQLITE_ENABLE_JSON1 " +
105+
"-DSQLITE_ENABLE_FTS3_PARENTHESIS " +
106+
"-DSQLITE_ENABLE_FTS4 " +
107+
"-DSQLITE_ENABLE_FTS5 " +
108+
"-DSQLCIPHER_CRYPTO_OPENSSL " +
109+
"-DSQLITE_ENABLE_DBSTAT_VTAB"
110+
}
95111
}
96112

97113
task clean(type: Delete) {

0 commit comments

Comments
 (0)