Skip to content

Commit 7e06621

Browse files
Build including native libraries
1 parent 158e8b9 commit 7e06621

File tree

5 files changed

+105
-37
lines changed

5 files changed

+105
-37
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ android-database-sqlcipher/src/main/external/sqlcipher
55
android-database-sqlcipher/src/main/external/openssl
66
android-database-sqlcipher/src/main/external/android-libs/
77
android-database-sqlcipher/.externalNativeBuild/
8+
android-database-sqlcipher/src/main/libs*
9+
android-database-sqlcipher/src/main/obj
Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
apply plugin: 'com.android.library'
1+
apply plugin: "com.android.library"
2+
apply from: "native.gradle"
23

34
android {
45

@@ -9,56 +10,34 @@ android {
910
minSdkVersion 14
1011
targetSdkVersion 26
1112
versionCode 1
12-
versionName "1.0"
13+
versionName "${rootProject.ext.clientVersionNumber}"
1314
}
1415

1516
buildTypes {
1617
release {
1718
minifyEnabled false
18-
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1919
}
2020
}
2121

22-
externalNativeBuild {
23-
ndkBuild {
24-
path "${projectDir}/src/main/cpp/Android.mk"
22+
sourceSets {
23+
main {
24+
jniLibs.srcDirs "${rootProject.ext.nativeRootOutputDir}/libs32/",
25+
"${rootProject.ext.nativeRootOutputDir}/libs64/"
2526
}
2627
}
2728

28-
task buildOpenSSL (type:Exec) {
29-
workingDir "${projectDir}"
30-
commandLine "./build-openssl-libraries.sh"
29+
task distclean(dependsOn: [clean, cleanSQLCipher, cleanOpenSSL]) {
30+
description "Clean up build, SQLCipher, and OpenSSL artifacts"
3131
}
3232

33-
task buildAmalgamation () {
34-
doLast {
35-
exec {
36-
workingDir "${projectDir}/src/main/external/sqlcipher"
37-
environment("CFLAGS", "${rootProject.ext.sqlcipherCFlags}")
38-
commandLine "./configure", "--enable-tempstore=yes", "--with-crypto-lib=none"
39-
}
40-
exec {
41-
workingDir "${projectDir}/src/main/external/sqlcipher"
42-
environment("CFLAGS", "${rootProject.ext.sqlcipherCFlags}")
43-
commandLine "make", "sqlite3.c"
44-
}
45-
}
46-
}
33+
clean.dependsOn cleanNative
4734

4835
preBuild.dependsOn buildAmalgamation
4936

50-
// task cleanOpenSSL() {
51-
// println "OpenSSL dir:${rootProject.ext.opensslDir}"
52-
// println "Cleaning OpenSSL"
53-
// }
54-
55-
// task cleanSQLCipher() {
56-
// println "SQLCipher dir:${rootProject.ext.sqlcipherDir}"
57-
// println "Cleaning SQLCipher"
58-
// }
59-
60-
}
37+
afterEvaluate {
38+
android.libraryVariants.all { variant ->
39+
variant.javaCompile.dependsOn([buildNative32, buildNative64])
40+
}
41+
}
6142

62-
dependencies {
63-
compile fileTree(dir: 'libs', include: ['*.jar'])
6443
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
task buildOpenSSL (type:Exec) {
2+
workingDir "${projectDir}"
3+
commandLine "./build-openssl-libraries.sh"
4+
}
5+
6+
task buildAmalgamation () {
7+
doLast {
8+
exec {
9+
workingDir "${projectDir}/src/main/external/sqlcipher"
10+
environment("CFLAGS", "${rootProject.ext.sqlcipherCFlags}")
11+
commandLine "./configure", "--enable-tempstore=yes", "--with-crypto-lib=none"
12+
}
13+
exec {
14+
workingDir "${projectDir}/src/main/external/sqlcipher"
15+
environment("CFLAGS", "${rootProject.ext.sqlcipherCFlags}")
16+
commandLine "make", "sqlite3.c"
17+
}
18+
}
19+
}
20+
21+
task buildNative32() {
22+
description "Build the 32-bit native SQLCipher binaries"
23+
doLast {
24+
executeNdkBuild(
25+
"${rootProject.ext.nativeRootOutputDir}/libs32",
26+
file("src/main/cpp").absolutePath,
27+
file("src/main/cpp/Application32.mk").absolutePath,
28+
"${rootProject.ext.sqlcipherCFlags}")
29+
}
30+
}
31+
32+
task buildNative64() {
33+
description "Build the 64-bit native SQLCipher binaries"
34+
doLast {
35+
executeNdkBuild(
36+
"${rootProject.ext.nativeRootOutputDir}/libs64",
37+
file("src/main/cpp").absolutePath,
38+
file("src/main/cpp/Application64.mk").absolutePath,
39+
"${rootProject.ext.sqlcipherCFlags}")
40+
}
41+
}
42+
43+
task cleanOpenSSL {
44+
description "Clean the OpenSSL source"
45+
doLast {
46+
logger.info "Cleaning OpenSSL directory:${rootProject.ext.opensslDir}"
47+
exec {
48+
workingDir "${rootProject.ext.opensslDir}"
49+
commandLine "git", "checkout", "-f"
50+
}
51+
}
52+
}
53+
54+
task cleanSQLCipher() {
55+
description "Clean the SQLCipher source"
56+
doLast {
57+
logger.info "Cleaning SQLCipher directory:${rootProject.ext.sqlcipherDir}"
58+
exec {
59+
workingDir "${rootProject.ext.sqlcipherDir}"
60+
commandLine "git", "checkout", "-f"
61+
}
62+
}
63+
}
64+
65+
task cleanNative() {
66+
description "Clean the native (JNI) build artifacts"
67+
doLast {
68+
logger.info "Cleaning native build artifacts"
69+
exec {
70+
workingDir "${projectDir}/src/main"
71+
commandLine "rm", "-rf", "libs32", "lib64", "obj"
72+
}
73+
}
74+
}
75+
76+
def executeNdkBuild(outputDir, androidMkDirectory, applicationMkFile, cflags) {
77+
logger.info "Executing NDK build command"
78+
exec {
79+
def outputDirectory = "NDK_LIBS_OUT=${outputDir}"
80+
def applicationFile = "NDK_APPLICATION_MK=${applicationMkFile}"
81+
environment("SQLCIPHER_CFLAGS", "${cflags}")
82+
commandLine "ndk-build", "--environment-overrides", outputDirectory,
83+
"-C", androidMkDirectory, applicationFile
84+
}
85+
}

android-database-sqlcipher/src/main/cpp/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SQLCIPHER_SRC := $(SQLCIPHER_DIR)/sqlite3.c
88
LOCAL_CFLAGS += $(SQLCIPHER_CFLAGS) -DLOG_NDEBUG
99
LOCAL_C_INCLUDES := $(SQLCIPHER_DIR) $(LOCAL_PATH)
1010
LOCAL_LDLIBS := -llog -latomic
11-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/android-libs/$(TARGET_ARCH_ABI) -fuse-ld=bfd
11+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../external/android-libs/$(TARGET_ARCH_ABI) -fuse-ld=bfd
1212
LOCAL_STATIC_LIBRARIES += static-libcrypto
1313
LOCAL_MODULE := libsqlcipher
1414
LOCAL_SRC_FILES := $(SQLCIPHER_SRC) \

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ allprojects {
1919
}
2020

2121
ext {
22+
clientVersionNumber = "3.5.7"
23+
nativeRootOutputDir = "${projectDir}/${name}/src/main"
2224
sqlcipherDir = "${projectDir}/${name}/src/main/external/sqlcipher"
2325
opensslDir = "${projectDir}/${name}/src/main/external/openssl"
2426
sqlcipherCFlags = "-DSQLITE_HAS_CODEC " +

0 commit comments

Comments
 (0)