Skip to content

Fix build on android ndk r9, merge libsqlcipher_android.so #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SECOND_LATEST_TAG := $(shell git tag | sort -r | head -2 | tail -1)
RELEASE_DIR := "SQLCipher for Android ${LATEST_TAG}"
CHANGE_LOG_HEADER := "Changes included in the ${LATEST_TAG} release of SQLCipher for Android:"
README := ${RELEASE_DIR}/README
MAKE_JOBS ?= 16

init:
git submodule update --init
Expand All @@ -20,13 +21,11 @@ all: build-external build-jni build-java copy-libs

build-external:
cd ${EXTERNAL_DIR} && \
make -f Android.mk build-local-hack && \
ndk-build && \
make -f Android.mk copy-libs-hack
make -f Android.mk build-local-hack

build-jni:
cd ${JNI_DIR} && \
ndk-build
cd ${CURDIR} && \
ndk-build -j${MAKE_JOBS}

build-java:
ant release && \
Expand All @@ -48,33 +47,12 @@ release:
clean:
-rm SQLCipher\ for\ Android\*.zip
ant clean
cd ${EXTERNAL_DIR} && ndk-build clean
cd ${CURDIR} && ndk-build clean
-cd ${SQLCIPHER_DIR} && make clean
cd ${JNI_DIR} && ndk-build clean
-rm ${LIBRARY_ROOT}/armeabi/libsqlcipher_android.so
-rm ${LIBRARY_ROOT}/armeabi/libdatabase_sqlcipher.so
-rm ${LIBRARY_ROOT}/armeabi/libstlport_shared.so
-rm ${LIBRARY_ROOT}/sqlcipher.jar
-rm ${LIBRARY_ROOT}/x86/libsqlcipher_android.so
-rm ${LIBRARY_ROOT}/x86/libdatabase_sqlcipher.so
-rm ${LIBRARY_ROOT}/x86/libstlport_shared.so

copy-libs:
mkdir -p ${LIBRARY_ROOT}/armeabi
cp ${EXTERNAL_DIR}/libs/armeabi/libsqlcipher_android.so \
${LIBRARY_ROOT}/armeabi && \
cp ${JNI_DIR}/libs/armeabi/libdatabase_sqlcipher.so \
${LIBRARY_ROOT}/armeabi && \
cp ${CURDIR}/bin/classes/sqlcipher.jar ${LIBRARY_ROOT} && \
cp ${EXTERNAL_DIR}/libs/armeabi/libstlport_shared.so \
${LIBRARY_ROOT}/armeabi
mkdir -p ${LIBRARY_ROOT}/x86
cp ${EXTERNAL_DIR}/libs/x86/libsqlcipher_android.so \
${LIBRARY_ROOT}/x86 && \
cp ${JNI_DIR}/libs/x86/libdatabase_sqlcipher.so \
${LIBRARY_ROOT}/x86 && \
cp ${EXTERNAL_DIR}/libs/x86/libstlport_shared.so \
${LIBRARY_ROOT}/x86
cp ${CURDIR}/bin/classes/sqlcipher.jar ${LIBRARY_ROOT}

copy-libs-dist:
cp ${LIBRARY_ROOT}/*.jar dist/SQLCipherForAndroid-SDK/libs/ && \
Expand Down
31 changes: 15 additions & 16 deletions external/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Before building using this do:
# make -f Android.mk build-local-hack
# ndk-build
# ndk-build
# make -f Android.mk copy-libs-hack

PROJECT_ROOT_PATH := $(call my-dir)
LOCAL_PATH := $(PROJECT_ROOT_PATH)
Expand All @@ -16,10 +14,8 @@ sqlcipher/sqlite3.c:
cd ${CURDIR}/sqlcipher && ./configure
make -C sqlcipher sqlite3.c

copy-libs-hack: build-local-hack
install -p -m644 libs/armeabi/*.so ../obj/local/armeabi/

project_ldflags:= -Llibs/$(TARGET_ARCH_ABI)/ -Landroid-libs/$(TARGET_ARCH_ABI)/
project_ldflags:= -L$(PROJECT_ROOT_PATH)/libs/$(TARGET_ARCH_ABI) \
-L$(PROJECT_ROOT_PATH)/android-libs/$(TARGET_ARCH_ABI)

#------------------------------------------------------------------------------#
# libsqlite3
Expand All @@ -41,8 +37,11 @@ sqlcipher_cflags := -DSQLITE_HAS_CODEC -DHAVE_FDATASYNC=0 -Dfdatasync=fsync

include $(CLEAR_VARS)

LOCAL_CFLAGS += $(android_sqlite_cflags) $(sqlcipher_cflags)
LOCAL_C_INCLUDES := includes openssl/include sqlcipher
LOCAL_CFLAGS += $(android_sqlite_cflags) $(sqlcipher_cflags) -fvisibility=hidden
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/includes \
$(LOCAL_PATH)/openssl/include \
$(LOCAL_PATH)/sqlcipher
LOCAL_LDFLAGS += $(project_ldflags)
LOCAL_LDLIBS += -lcrypto
LOCAL_MODULE := libsqlcipher
Expand Down Expand Up @@ -75,7 +74,7 @@ LOCAL_ALLOW_UNDEFINED_SYMBOLS := false
#LOCAL_REQUIRED_MODULES += libsqlcipher libicui18n libicuuc
LOCAL_STATIC_LIBRARIES := libsqlcipher libicui18n libicuuc

LOCAL_CFLAGS += $(android_sqlite_cflags) $(sqlite_cflags) \
LOCAL_CFLAGS += $(android_sqlite_cflags) $(sqlite_cflags) -fvisibility=hidden \
-DOS_PATH_SEPARATOR="'/'" -DHAVE_SYS_UIO_H

LOCAL_C_INCLUDES := \
Expand All @@ -86,13 +85,13 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/platform-system-core/include \
$(LOCAL_PATH)/platform-frameworks-base/include

LOCAL_LDFLAGS += -L${LOCAL_PATH}/android-libs/$(TARGET_ARCH_ABI)/ -L$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/
LOCAL_LDFLAGS += $(project_ldflags)
LOCAL_LDLIBS := -llog -lutils -lcutils -lcrypto
LOCAL_MODULE := libsqlcipher_android
LOCAL_MODULE_FILENAME := libsqlcipher_android
LOCAL_SRC_FILES := $(libsqlite3_android_local_src_files)

include $(BUILD_SHARED_LIBRARY)
include $(BUILD_STATIC_LIBRARY)

#-------------------------
# start icu project import
Expand All @@ -105,7 +104,7 @@ include $(BUILD_SHARED_LIBRARY)

#include $(CLEAR_VARS)

ICU_COMMON_PATH := icu4c/common
ICU_COMMON_PATH := $(LOCAL_PATH)/icu4c/common

# new icu common build begin

Expand Down Expand Up @@ -209,6 +208,7 @@ icu_c_includes := \
icu_local_cflags += -D_REENTRANT -DU_COMMON_IMPLEMENTATION -O3 -DHAVE_ANDROID_OS=1 -fvisibility=hidden
icu_local_cflags += '-DICU_DATA_DIR_PREFIX_ENV_VAR="SQLCIPHER_ICU_PREFIX"'
icu_local_cflags += '-DICU_DATA_DIR="/icu"'
icu_local_cflags += -include $(LOCAL_PATH)/VisibilityIcu.h
icu_local_ldlibs := -lc -lpthread -lm

#
Expand All @@ -219,8 +219,8 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(icu_src_files)
LOCAL_C_INCLUDES := $(icu_c_includes)
LOCAL_CFLAGS := $(icu_local_cflags) -DPIC -fPIC
LOCAL_EXPORT_CFLAGS := -include $(LOCAL_PATH)/VisibilityIcu.h
LOCAL_RTTI_FLAG := -frtti
LOCAL_SHARED_LIBRARIES += libgabi++
LOCAL_LDLIBS += $(icu_local_ldlibs)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libicuuc
Expand All @@ -235,8 +235,8 @@ include $(BUILD_STATIC_LIBRARY)
#--------------
include $(CLEAR_VARS)
LOCAL_PATH := $(PROJECT_ROOT_PATH)
#ICU_I18N_PATH := $(LOCAL_PATH)/icu4c/i18n
ICU_I18N_PATH := icu4c/i18n
ICU_I18N_PATH := $(LOCAL_PATH)/icu4c/i18n
#ICU_I18N_PATH := icu4c/i18n

# start new icu18n

Expand Down Expand Up @@ -313,7 +313,6 @@ LOCAL_C_INCLUDES := $(c_includes) \
LOCAL_CFLAGS += -D_REENTRANT -DPIC -DU_I18N_IMPLEMENTATION -fPIC -fvisibility=hidden
LOCAL_CFLAGS += -O3
LOCAL_RTTI_FLAG := -frtti
LOCAL_SHARED_LIBRARIES += libgabi++
LOCAL_STATIC_LIBRARIES += libicuuc
LOCAL_LDLIBS += -lc -lpthread -lm
LOCAL_MODULE_TAGS := optional
Expand Down
10 changes: 10 additions & 0 deletions external/VisibilityIcu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Dirty hack changing ICU visibility to hidden */

#ifndef _VISIBILITY_ICU_H
#define _VISIBILITY_ICU_H

#include <unicode/platform.h>
#undef U_EXPORT
#define U_EXPORT

#endif
21 changes: 8 additions & 13 deletions jni/Android.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LOCAL_PATH:= $(call my-dir)

EXTERNAL_PATH := ../external
EXTERNAL_PATH := $(LOCAL_PATH)/../external

LOCAL_CFLAGS += -DPACKED="__attribute__ ((packed))"

Expand Down Expand Up @@ -42,24 +42,18 @@ LOCAL_C_INCLUDES += \
$(EXTERNAL_PATH)/platform-frameworks-base/include \
$(EXTERNAL_PATH)/icu4c/common \

LOCAL_SHARED_LIBRARIES := \
libcrypto \
libssl \
libsqlcipher \
libsqlite3_android
#LOCAL_SHARED_LIBRARIES := libsqlcipher_android
LOCAL_STATIC_LIBRARIES := libsqlcipher_android libicuuc

LOCAL_CFLAGS += -U__APPLE__
LOCAL_LDFLAGS += -L../external/android-libs/$(TARGET_ARCH_ABI) -L../external/libs/$(TARGET_ARCH_ABI)/
LOCAL_LDFLAGS += -L$(EXTERNAL_PATH)/android-libs/$(TARGET_ARCH_ABI) -L$(EXTERNAL_PATH)/libs/$(TARGET_ARCH_ABI)/

# libs from the NDK
LOCAL_LDLIBS += -ldl -llog
# libnativehelper and libandroid_runtime are included with Android but not the NDK
LOCAL_LDLIBS += -lnativehelper -landroid_runtime -lutils -lbinder
# these are build in the ../external section
LOCAL_LDLIBS += -lnativehelper -landroid_runtime -lutils -lbinder -lcrypto

LOCAL_LDLIBS += -lsqlcipher_android
LOCAL_LDFLAGS += -L../obj/local/$(TARGET_ARCH_ABI)
LOCAL_LDLIBS += -licui18n -licuuc
# these are build in the ../external section

ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
Expand All @@ -69,4 +63,5 @@ LOCAL_MODULE:= libdatabase_sqlcipher

include $(BUILD_SHARED_LIBRARY)

include $(call all-makefiles-under,$(LOCAL_PATH))
$(call import-module,external)

4 changes: 3 additions & 1 deletion jni/Application.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
APP_PROJECT_PATH := $(shell pwd)
APP_ABI := armeabi x86
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
#APP_PLATFORM := android-8
NDK_MODULE_PATH=$(APP_PROJECT_PATH)
# fixes this error when building external/android-sqlite/android/sqlite3_android.cpp
# icu4c/common/unicode/std_string.h:39:18: error: string: No such file or directory
APP_STL := stlport_shared

1 change: 0 additions & 1 deletion src/net/sqlcipher/database/SQLiteDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public static void loadLibs (Context context) {
public static void loadLibs (Context context, File workingDir)
{
System.loadLibrary("stlport_shared");
System.loadLibrary("sqlcipher_android");
System.loadLibrary("database_sqlcipher");

boolean systemICUFileExists = new File("/system/usr/icu/icudt46l.dat").exists();
Expand Down