Skip to content

Commit 7286724

Browse files
Update build to use Android NDK r20 toolchain and OpenSSL 1.1.1d
NOTE: The armeabi ABI is no longer supported (due to toolchain update), and the minimum supported Android API is now 16 (previously 14).
1 parent b58e433 commit 7286724

13 files changed

+59
-84
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ android-database-sqlcipher/.externalNativeBuild/
88
android-database-sqlcipher/src/main/libs*
99
android-database-sqlcipher/src/main/obj
1010
android-database-sqlcipher/src/main/external/openssl-*/
11+
android-database-sqlcipher/src/main/cpp/sqlite3.[c,h]
1112
.idea/
1213
*.iml
1314
local.properties

Diff for: README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The latest AAR binary package information can be [here](https://www.zetetic.net/
55

66
### Compatibility
77

8-
SQLCipher for Android runs on Android 4–Android 9, for `armeabi`, `armeabi-v7a`, `x86`, `x86_64`, and `arm64_v8a` architectures.
8+
SQLCipher for Android runs on Android 4.1–Android 10, for `armeabi-v7a`, `x86`, `x86_64`, and `arm64_v8a` architectures.
99

1010
### Contributions
1111

@@ -76,6 +76,9 @@ There are two `SupportFactory` constructors:
7676
for executing SQL statements before or after the passphrase is used to decrypt
7777
the database
7878

79+
- One constructor option includes a boolean parameter to opt out of the clearing
80+
the passphrase used to access the SQLCipher database.
81+
7982
Then, pass your `SupportFactory` to `openHelperFactory()` on your `RoomDatabase.Builder`:
8083

8184
```java
@@ -114,7 +117,7 @@ An article covering both integration of SQLCipher into an Android application as
114117

115118
### Building
116119

117-
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 `r15c`, however we plan to update to a newer NDK release when possible. To complete the `make` command, the `ANDROID_NDK_ROOT` 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:
120+
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:
118121

119122
```
120123
# this only needs to be done once

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

+22-63
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,11 @@ OPENSSL=openssl-$3
2020
exit 1
2121
fi
2222

23-
if [[ ! ${ANDROID_NDK_ROOT} ]]; then
24-
echo "ANDROID_NDK_ROOT environment variable not set, set and rerun"
23+
if [[ ! ${ANDROID_NDK_HOME} ]]; then
24+
echo "ANDROID_NDK_HOME environment variable not set, set and rerun"
2525
exit 1
2626
fi
2727

28-
NDK_TOOLCHAIN_VERSION=4.9
29-
ANDROID_LIB_ROOT=../android-libs
30-
ANDROID_TOOLCHAIN_DIR=/tmp/sqlcipher-android-toolchain
31-
OPENSSL_CONFIGURE_OPTIONS="-fPIC no-idea no-camellia \
32-
no-seed no-bf no-cast no-rc2 no-rc4 no-rc5 no-md2 \
33-
no-md4 no-ecdh no-sock no-ssl3 \
34-
no-dsa no-dh no-ec no-ecdsa no-tls1 \
35-
no-rfc3779 no-whirlpool no-srp \
36-
no-mdc2 no-ecdh no-engine \
37-
no-srtp"
38-
3928
HOST_INFO=`uname -a`
4029
case ${HOST_INFO} in
4130
Darwin*)
@@ -55,97 +44,67 @@ OPENSSL=openssl-$3
5544
;;
5645
esac
5746

47+
NDK_TOOLCHAIN_VERSION=4.9
48+
ANDROID_LIB_ROOT=../android-libs
49+
OPENSSL_CONFIGURE_OPTIONS="-fPIC -fstack-protector-all no-idea no-camellia \
50+
no-seed no-bf no-cast no-rc2 no-rc4 no-rc5 no-md2 \
51+
no-md4 no-ecdh no-sock no-ssl3 \
52+
no-dsa no-dh no-ec no-ecdsa no-tls1 \
53+
no-rfc3779 no-whirlpool no-srp \
54+
no-mdc2 no-ecdh no-engine \
55+
no-srtp"
56+
5857
rm -rf ${ANDROID_LIB_ROOT}
5958

60-
for SQLCIPHER_TARGET_PLATFORM in armeabi armeabi-v7a x86 x86_64 arm64-v8a
59+
for SQLCIPHER_TARGET_PLATFORM in armeabi-v7a x86 x86_64 arm64-v8a
6160
do
6261
echo "Building libcrypto.a for ${SQLCIPHER_TARGET_PLATFORM}"
6362
case "${SQLCIPHER_TARGET_PLATFORM}" in
64-
armeabi)
65-
TOOLCHAIN_ARCH=arm
66-
TOOLCHAIN_PREFIX=arm-linux-androideabi
67-
TOOLCHAIN_FOLDER=arm-linux-androideabi
68-
CONFIGURE_ARCH=android-arm
69-
ANDROID_API_VERSION=${MINIMUM_ANDROID_SDK_VERSION}
70-
OFFSET_BITS=32
71-
TOOLCHAIN_DIR=${ANDROID_TOOLCHAIN_DIR}-armeabi
72-
;;
7363
armeabi-v7a)
74-
TOOLCHAIN_ARCH=arm
75-
TOOLCHAIN_PREFIX=arm-linux-androideabi
76-
TOOLCHAIN_FOLDER=arm-linux-androideabi
7764
CONFIGURE_ARCH="android-arm -march=armv7-a"
7865
ANDROID_API_VERSION=${MINIMUM_ANDROID_SDK_VERSION}
7966
OFFSET_BITS=32
80-
TOOLCHAIN_DIR=${ANDROID_TOOLCHAIN_DIR}-armeabi-v7a
8167
;;
8268
x86)
83-
TOOLCHAIN_ARCH=x86
84-
TOOLCHAIN_PREFIX=i686-linux-android
85-
TOOLCHAIN_FOLDER=x86
8669
CONFIGURE_ARCH=android-x86
8770
ANDROID_API_VERSION=${MINIMUM_ANDROID_SDK_VERSION}
8871
OFFSET_BITS=32
89-
TOOLCHAIN_DIR=${ANDROID_TOOLCHAIN_DIR}-x86
9072
;;
9173
x86_64)
92-
TOOLCHAIN_ARCH=x86_64
93-
TOOLCHAIN_PREFIX=x86_64-linux-android
94-
TOOLCHAIN_FOLDER=x86_64
9574
CONFIGURE_ARCH=android64-x86_64
9675
ANDROID_API_VERSION=${MINIMUM_ANDROID_64_BIT_SDK_VERSION}
9776
OFFSET_BITS=64
98-
TOOLCHAIN_DIR=${ANDROID_TOOLCHAIN_DIR}-x86_64
9977
;;
10078
arm64-v8a)
101-
TOOLCHAIN_ARCH=arm64
102-
TOOLCHAIN_PREFIX=aarch64-linux-android
103-
TOOLCHAIN_FOLDER=aarch64-linux-android
10479
CONFIGURE_ARCH=android-arm64
10580
ANDROID_API_VERSION=${MINIMUM_ANDROID_64_BIT_SDK_VERSION}
10681
OFFSET_BITS=64
107-
TOOLCHAIN_DIR=${ANDROID_TOOLCHAIN_DIR}-arm64-v8a
10882
;;
10983
*)
11084
echo "Unsupported build platform:${SQLCIPHER_TARGET_PLATFORM}"
11185
exit 1
11286
esac
113-
SOURCE_TOOLCHAIN_DIR=${ANDROID_NDK_ROOT}/toolchains/${TOOLCHAIN_FOLDER}-${NDK_TOOLCHAIN_VERSION}/prebuilt/${TOOLCHAIN_SYSTEM}
114-
rm -rf ${TOOLCHAIN_DIR}
115-
mkdir -p "${ANDROID_LIB_ROOT}/${SQLCIPHER_TARGET_PLATFORM}"
116-
python ${ANDROID_NDK_ROOT}/build/tools/make_standalone_toolchain.py \
117-
--arch ${TOOLCHAIN_ARCH} \
118-
--api ${ANDROID_API_VERSION} \
119-
--install-dir ${TOOLCHAIN_DIR} \
120-
--unified-headers
121-
122-
if [[ $? -ne 0 ]]; then
123-
echo "Error executing make_standalone_toolchain.py for ${TOOLCHAIN_ARCH}"
124-
exit 1
125-
fi
126-
127-
export PATH=${TOOLCHAIN_DIR}/bin:${PATH}
128-
129-
ANDROID_NDK=${ANDROID_NDK_ROOT} \
130-
PATH=${SOURCE_TOOLCHAIN_DIR}/bin:${PATH} \
131-
./Configure ${CONFIGURE_ARCH} \
132-
-D__ANDROID_API__=${ANDROID_API_VERSION} \
133-
-D_FILE_OFFSET_BITS=${OFFSET_BITS} \
134-
${OPENSSL_CONFIGURE_OPTIONS} \
135-
--sysroot=${TOOLCHAIN_DIR}/sysroot
87+
TOOLCHAIN_BIN_PATH=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${TOOLCHAIN_SYSTEM}/bin
88+
PATH=${TOOLCHAIN_BIN_PATH}:${PATH} \
89+
./Configure ${CONFIGURE_ARCH} \
90+
-D__ANDROID_API__=${ANDROID_API_VERSION} \
91+
-D_FILE_OFFSET_BITS=${OFFSET_BITS} \
92+
${OPENSSL_CONFIGURE_OPTIONS}
13693

13794
if [[ $? -ne 0 ]]; then
13895
echo "Error executing:./Configure ${CONFIGURE_ARCH} ${OPENSSL_CONFIGURE_OPTIONS}"
13996
exit 1
14097
fi
14198

14299
make clean
143-
make build_libs
100+
PATH=${TOOLCHAIN_BIN_PATH}:${PATH} \
101+
make build_libs
144102

145103
if [[ $? -ne 0 ]]; then
146104
echo "Error executing make for platform:${SQLCIPHER_TARGET_PLATFORM}"
147105
exit 1
148106
fi
107+
mkdir -p ${ANDROID_LIB_ROOT}/${SQLCIPHER_TARGET_PLATFORM}
149108
mv libcrypto.a ${ANDROID_LIB_ROOT}/${SQLCIPHER_TARGET_PLATFORM}
150109
done
151110
)

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

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ android {
4141
implementation "androidx.sqlite:sqlite:2.0.1"
4242
}
4343

44+
editorconfig {
45+
excludes = ['src/main/cpp/sqlite3.*',
46+
'src/main/external/sqlcipher/**',
47+
'src/main/external/openssl-*/**']
48+
}
49+
4450
clean.dependsOn cleanNative
4551
check.dependsOn editorconfigCheck
4652
buildNative.mustRunAfter buildAmalgamation

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import static org.gradle.internal.logging.text.StyledTextOutput.Style
33

44
task buildOpenSSL() {
55
onlyIf {
6-
def armNativeFile = new File("${androidNativeRootDir}/armeabi/libcrypto.a")
6+
def armNativeFile = new File("${androidNativeRootDir}/armeabi-v7a/libcrypto.a")
77
if (armNativeFile.exists()) {
88
def out = services.get(StyledTextOutputFactory).create("")
9-
out.style(Style.Normal).text("${androidNativeRootDir}/armeabi/libcrypto.a exists").style(Style.Info).println(' SKIPPED')
9+
out.style(Style.Normal).text("${androidNativeRootDir}/armeabi-v7a/libcrypto.a exists").style(Style.Info).println(' SKIPPED')
1010
}
1111
return !armNativeFile.exists()
1212
}
@@ -23,7 +23,7 @@ task buildOpenSSL() {
2323

2424
task buildAmalgamation() {
2525
onlyIf {
26-
def amalgamation = new File("${projectDir}/src/main/external/sqlcipher/sqlite3.c")
26+
def amalgamation = new File("${projectDir}/src/main/cpp/sqlite3.c")
2727
return !amalgamation.exists()
2828
}
2929
doLast {
@@ -37,6 +37,10 @@ task buildAmalgamation() {
3737
environment("CFLAGS", "${sqlcipherCFlags}")
3838
commandLine "make", "sqlite3.c"
3939
}
40+
exec {
41+
workingDir "${projectDir}/src/main/external/sqlcipher"
42+
commandLine "cp", "sqlite3.c", "sqlite3.h", "${nativeRootOutputDir}/cpp/"
43+
}
4044
}
4145
}
4246

@@ -86,8 +90,12 @@ task cleanSQLCipher() {
8690
gitClean("${sqlcipherDir}")
8791
File amalgamationSource = new File("${sqlcipherDir}/sqlite3.c")
8892
File amalgamationHeader = new File("${sqlcipherDir}/sqlite3.h")
93+
File amalgamationDestinationSource = new File("${nativeRootOutputDir}/cpp/sqlite3.c")
94+
File amalgamationDestinationHeader = new File("${nativeRootOutputDir}/cpp/sqlite3.h")
8995
if (amalgamationSource.exists()) amalgamationSource.delete()
9096
if (amalgamationHeader.exists()) amalgamationHeader.delete()
97+
if (amalgamationDestinationSource.exists()) amalgamationDestinationSource.delete()
98+
if (amalgamationDestinationHeader.exists()) amalgamationDestinationHeader.delete()
9199
}
92100
}
93101

@@ -145,7 +153,7 @@ def executeNdkBuild(outputDir, androidMkDirectory, applicationMkFile,
145153
"ANDROID_NATIVE_ROOT_DIR": "${androidNativeRootDir}",
146154
"NDK_APP_PLATFORM" : "${androidVersion}"]
147155
environment(environmentVariables)
148-
commandLine "ndk-build", "${ndkBuildType}",
156+
commandLine "ndk-build", "V=1", "${ndkBuildType}",
149157
"--environment-overrides", outputDirectory,
150158
"-C", androidMkDirectory, applicationFile
151159
}

Diff for: android-database-sqlcipher/src/main/cpp/Android.mk

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ MY_PATH := $(LOCAL_PATH)
33
include $(CLEAR_VARS)
44
LOCAL_PATH := $(MY_PATH)
55

6-
SQLCIPHER_SRC := $(SQLCIPHER_DIR)/sqlite3.c
76
LOCAL_CFLAGS += $(SQLCIPHER_CFLAGS) $(SQLCIPHER_OTHER_CFLAGS)
8-
LOCAL_C_INCLUDES := $(SQLCIPHER_DIR) $(LOCAL_PATH)
9-
LOCAL_LDLIBS := -llog -latomic
7+
LOCAL_C_INCLUDES += $(LOCAL_PATH)
8+
LOCAL_LDLIBS := -llog
109
LOCAL_LDFLAGS += -L$(ANDROID_NATIVE_ROOT_DIR)/$(TARGET_ARCH_ABI) -fuse-ld=bfd
1110
LOCAL_STATIC_LIBRARIES += static-libcrypto
1211
LOCAL_MODULE := libsqlcipher
13-
LOCAL_SRC_FILES := $(SQLCIPHER_SRC) \
12+
LOCAL_SRC_FILES := sqlite3.c \
1413
jni_exception.cpp \
1514
net_sqlcipher_database_SQLiteCompiledSql.cpp \
1615
net_sqlcipher_database_SQLiteDatabase.cpp \
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
APP_PROJECT_PATH := $(shell pwd)
2-
APP_ABI := armeabi armeabi-v7a x86
2+
APP_ABI := armeabi-v7a x86
33
APP_PLATFORM := android-$(NDK_APP_PLATFORM)
44
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
5-
APP_STL := stlport_static
5+
APP_STL := c++_static
66
APP_CFLAGS := -D_FILE_OFFSET_BITS=32
77
APP_LDFLAGS += -Wl,--exclude-libs,ALL

Diff for: android-database-sqlcipher/src/main/cpp/Application64.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ APP_PROJECT_PATH := $(shell pwd)
22
APP_ABI := x86_64 arm64-v8a
33
APP_PLATFORM := android-$(NDK_APP_PLATFORM)
44
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
5-
APP_STL := stlport_static
5+
APP_STL := c++_static
66
APP_CFLAGS := -D_FILE_OFFSET_BITS=64
77
APP_LDFLAGS += -Wl,--exclude-libs,ALL

Diff for: android-database-sqlcipher/src/main/cpp/CursorWindow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#define WINDOW_STORAGE_INLINE_NUMERICS 1
5656

5757
using std::make_pair;
58-
using std::tr1::unordered_map;
58+
using std::unordered_map;
5959

6060
namespace sqlcipher {
6161

Diff for: android-database-sqlcipher/src/main/cpp/jni_exception.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <cstddef>
21
#include "jni_exception.h"
32

43
void jniThrowException(JNIEnv* env, const char* exceptionClass, const char* sqlite3Message) {

Diff for: android-database-sqlcipher/src/main/cpp/net_sqlcipher_CursorWindow.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ namespace sqlcipher {
285285
int64_t value;
286286
if (window->getLong(row, column, &value)) {
287287
char buf[32];
288-
snprintf(buf, sizeof(buf), "%"PRId64"", value);
288+
snprintf(buf, sizeof(buf), "%" PRId64 "", value);
289289
return env->NewStringUTF((const char*)buf);
290290
}
291291
return NULL;
@@ -361,7 +361,7 @@ namespace sqlcipher {
361361
if (window->getLong(row, column, &value)) {
362362
int len;
363363
char buf[32];
364-
len = snprintf(buf, sizeof(buf), "%"PRId64"", value);
364+
len = snprintf(buf, sizeof(buf), "%" PRId64 "", value);
365365
jint bufferLength = env->GetArrayLength(buffer);
366366
if(len > bufferLength || dst == NULL){
367367
jstring content = env->NewStringUTF(buf);

Diff for: build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ ext {
5454
mavenDeveloperEmail = "support@zetetic.net"
5555
mavenDeveloperOrganization = "Zetetic LLC"
5656
mavenDeveloperUrl = "https://www.zetetic.net"
57-
minimumAndroidSdkVersion = 14
57+
minimumAndroidSdkVersion = 16
5858
minimumAndroid64BitSdkVersion = 21
5959
targetAndroidSdkVersion = 26
6060
compileAndroidSdkVersion = 26
6161
mainProjectName = "android-database-sqlcipher"
6262
nativeRootOutputDir = "${projectDir}/${mainProjectName}/src/main"
6363
androidNativeRootDir = "${nativeRootOutputDir}/external/android-libs"
6464
sqlcipherDir = "${projectDir}/${mainProjectName}/src/main/external/sqlcipher"
65-
opensslVersion = "1.1.1b"
65+
opensslVersion = "1.1.1d"
6666
opensslDir = "${projectDir}/${mainProjectName}/src/main/external/openssl-${opensslVersion}"
6767
if(project.hasProperty('debugBuild') && debugBuild.toBoolean()) {
68-
otherSqlcipherCFlags = ""
68+
otherSqlcipherCFlags = "-fstack-protector-all"
6969
ndkBuildType="NDK_DEBUG=1"
7070
} else {
71-
otherSqlcipherCFlags = "-DLOG_NDEBUG"
71+
otherSqlcipherCFlags = "-DLOG_NDEBUG -fstack-protector-all"
7272
ndkBuildType="NDK_DEBUG=0"
7373
}
7474
sqlcipherCFlags = "-DSQLITE_HAS_CODEC " +

0 commit comments

Comments
 (0)