Skip to content

Commit b95023d

Browse files
Build with static OpenSSL libraries
New script to build static OpenSSL libraries which are then included as a local module - current libraries are based on the 1.0.1e tag of OpenSSL.
1 parent cd0923b commit b95023d

File tree

7 files changed

+75
-7
lines changed

7 files changed

+75
-7
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ release:
4747

4848
clean:
4949
-rm SQLCipher\ for\ Android\*.zip
50-
ant clean
51-
cd ${EXTERNAL_DIR} && ndk-build clean
50+
-ant clean
51+
-cd ${EXTERNAL_DIR} && ndk-build clean
5252
-cd ${SQLCIPHER_DIR} && make clean
53-
cd ${JNI_DIR} && ndk-build clean
53+
-cd ${JNI_DIR} && ndk-build clean
5454
-rm ${LIBRARY_ROOT}/armeabi/libsqlcipher_android.so
5555
-rm ${LIBRARY_ROOT}/armeabi/libdatabase_sqlcipher.so
5656
-rm ${LIBRARY_ROOT}/armeabi/libstlport_shared.so
@@ -79,3 +79,6 @@ copy-libs:
7979
copy-libs-dist:
8080
cp ${LIBRARY_ROOT}/*.jar dist/SQLCipherForAndroid-SDK/libs/ && \
8181
cp ${LIBRARY_ROOT}/armeabi/*.so dist/SQLCipherForAndroid-SDK/libs/armeabi/
82+
83+
build-openssl-libraries:
84+
./build-openssl-libraries.sh

build-openssl-libraries.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(cd external/openssl;
2+
3+
if [ ! ${ANDROID_NDK_ROOT} ]; then
4+
echo "ANDROID_NDK_ROOT environment variable not set, set and rerun"
5+
exit 1
6+
fi
7+
8+
rm ../android-libs/armeabi/libcrypto.a \
9+
../android-libs/x86/libcrypto.a
10+
11+
git clean -dfx && git checkout -f
12+
./Configure dist
13+
14+
ANDROID_PLATFORM_VERSION=android-14
15+
ANDROID_TOOLCHAIN_DIR=/tmp/sqlcipher-android-toolchain
16+
OPENSSL_EXCLUSION_LIST=no-krb5 no-gost no-idea no-camellia \
17+
no-seed no-bf no-cast no-rc2 no-rc4 no-rc5 no-md2 \
18+
no-md4 no-ripemd no-rsa no-ecdh no-sock no-ssl2 no-ssl3 \
19+
no-dsa no-dh no-ec no-ecdsa no-tls1 no-x509 no-pkcs7 \
20+
no-pbe no-pkcs no-tlsext no-pem no-rfc3779 no-whirlpool \
21+
no-ocsp no-x509v3 no-ui no-srp no-ssltrace no-tlsext \
22+
no-mdc2 no-ecdh no-engine no-tls2 no-srtp
23+
24+
${ANDROID_NDK_ROOT}/build/tools/make-standalone-toolchain.sh \
25+
--platform=${ANDROID_PLATFORM_VERSION} \
26+
--install-dir=${ANDROID_TOOLCHAIN_DIR} \
27+
--system=darwin-x86_64 \
28+
--arch=arm
29+
30+
export PATH=${ANDROID_TOOLCHAIN_DIR}/bin:$PATH
31+
32+
RANLIB=arm-linux-androideabi-ranlib \
33+
AR=arm-linux-androideabi-ar \
34+
CC=arm-linux-androideabi-gcc \
35+
./Configure android ${OPENSSL_EXCLUSION_LIST}
36+
37+
make build_crypto
38+
39+
mv libcrypto.a ../android-libs/armeabi/
40+
41+
rm -rf ${ANDROID_TOOLCHAIN_DIR}
42+
43+
${ANDROID_NDK_ROOT}/build/tools/make-standalone-toolchain.sh \
44+
--platform=${ANDROID_PLATFORM_VERSION} \
45+
--install-dir=${ANDROID_TOOLCHAIN_DIR} \
46+
--system=darwin-x86_64 \
47+
--arch=x86
48+
49+
export PATH=${ANDROID_TOOLCHAIN_DIR}/bin:$PATH
50+
51+
RANLIB=i686-linux-android-ranlib \
52+
AR=i686-linux-android-ar \
53+
CC=i686-linux-android-gcc \
54+
./Configure android-x86 ${OPENSSL_EXCLUSION_LIST}
55+
56+
make build_crypto
57+
58+
mv libcrypto.a ../android-libs/x86/
59+
)

external/Android.mk

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,21 @@ sqlcipher_cflags := -DSQLITE_HAS_CODEC -DHAVE_FDATASYNC=0 -Dfdatasync=fsync
4141

4242
include $(CLEAR_VARS)
4343

44+
LOCAL_STATIC_LIBRARIES += static-libcrypto
4445
LOCAL_CFLAGS += $(android_sqlite_cflags) $(sqlcipher_cflags)
45-
LOCAL_C_INCLUDES := includes openssl/include sqlcipher
46+
LOCAL_C_INCLUDES := includes sqlcipher
4647
LOCAL_LDFLAGS += $(project_ldflags)
47-
LOCAL_LDLIBS += -lcrypto
4848
LOCAL_MODULE := libsqlcipher
4949
LOCAL_SRC_FILES := $(sqlcipher_files)
5050

5151
include $(BUILD_STATIC_LIBRARY)
5252

53+
include $(CLEAR_VARS)
54+
LOCAL_MODULE := static-libcrypto
55+
LOCAL_EXPORT_C_INCLUDES := openssl/include
56+
LOCAL_SRC_FILES := android-libs/$(TARGET_ARCH_ABI)/libcrypto.a
57+
include $(PREBUILT_STATIC_LIBRARY)
58+
5359
#------------------------------------------------------------------------------#
5460
# libsqlcipher_android (our version of Android's libsqlite_android)
5561

@@ -73,7 +79,7 @@ LOCAL_ALLOW_UNDEFINED_SYMBOLS := false
7379

7480
# TODO this needs to depend on libsqlcipher being built, how to do that?
7581
#LOCAL_REQUIRED_MODULES += libsqlcipher libicui18n libicuuc
76-
LOCAL_STATIC_LIBRARIES := libsqlcipher libicui18n libicuuc
82+
LOCAL_STATIC_LIBRARIES := libsqlcipher libicui18n libicuuc static-libcrypto
7783

7884
LOCAL_CFLAGS += $(android_sqlite_cflags) $(sqlite_cflags) \
7985
-DOS_PATH_SEPARATOR="'/'" -DHAVE_SYS_UIO_H
@@ -87,7 +93,7 @@ LOCAL_C_INCLUDES := \
8793
$(LOCAL_PATH)/platform-frameworks-base/include
8894

8995
LOCAL_LDFLAGS += -L${LOCAL_PATH}/android-libs/$(TARGET_ARCH_ABI)/ -L$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/
90-
LOCAL_LDLIBS := -llog -lutils -lcutils -lcrypto
96+
LOCAL_LDLIBS := -llog -lutils -lcutils
9197
LOCAL_MODULE := libsqlcipher_android
9298
LOCAL_MODULE_FILENAME := libsqlcipher_android
9399
LOCAL_SRC_FILES := $(libsqlite3_android_local_src_files)
2.51 MB
Binary file not shown.
-729 KB
Binary file not shown.
3.06 MB
Binary file not shown.
-1.54 MB
Binary file not shown.

0 commit comments

Comments
 (0)