Skip to content

Commit bf45bb3

Browse files
Introduce new build targets to allow for debug and release builds
1 parent 7a22927 commit bf45bb3

File tree

8 files changed

+1519
-1457
lines changed

8 files changed

+1519
-1457
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.POSIX:
22
.PHONY: init clean distclean build-openssl build publish-local-snapshot \
33
publish-local-release publish-remote-snapshot public-remote-release
4-
GRADLE = ./gradlew
4+
GRADLE = @./gradlew
55

66
init:
77
git submodule update --init
@@ -15,8 +15,13 @@ distclean:
1515
build-openssl:
1616
$(GRADLE) buildOpenSSL
1717

18-
build:
19-
$(GRADLE) android-database-sqlcipher:bundleRelease
18+
build-debug:
19+
$(GRADLE) android-database-sqlcipher:bundleDebugAar \
20+
-PdebugBuild=true
21+
22+
build-release:
23+
$(GRADLE) android-database-sqlcipher:bundleReleaseAar \
24+
-PdebugBuild=false
2025

2126
publish-local-snapshot:
2227
@ $(collect-signing-info) \

README.org

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ In order to build android-database-sqlcipher from source you will need both the
6060
: # this only needs to be done once
6161
: make init
6262

63-
: # to build the source
64-
: make build
63+
: # to build the source for debug:
64+
: make build-debug
65+
: # or for a release build:
66+
: make build-release
6567

6668
*** License
6769

android-database-sqlcipher/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ android {
1515
}
1616

1717
buildTypes {
18+
debug {
19+
debuggable true
20+
}
1821
release {
22+
debuggable false
1923
minifyEnabled false
2024
}
2125
}
@@ -36,7 +40,8 @@ android {
3640
variant.outputs.each { output ->
3741
def outputFile = output.outputFile
3842
if (outputFile != null && outputFile.name.endsWith(".aar")) {
39-
def versionFileName = "${archivesBaseName}-${clientVersionNumber}.aar"
43+
def buildSuffix = variant.buildType.debuggable ? "-debug" : ""
44+
def versionFileName = "${archivesBaseName}-${clientVersionNumber}${buildSuffix}.aar"
4045
output.outputFileName = versionFileName
4146
}
4247
}

android-database-sqlcipher/native.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ task buildNative() {
3939
"${nativeRootOutputDir}/libs32",
4040
file("src/main/cpp").absolutePath,
4141
file("src/main/cpp/Application32.mk").absolutePath,
42-
"${sqlcipherCFlags}")
42+
"${sqlcipherCFlags}", "${otherSqlcipherCFlags}")
4343
executeNdkBuild(
4444
"${nativeRootOutputDir}/libs64",
4545
file("src/main/cpp").absolutePath,
4646
file("src/main/cpp/Application64.mk").absolutePath,
47-
"${sqlcipherCFlags}")
47+
"${sqlcipherCFlags}", "${otherSqlcipherCFlags}")
4848
exec {
4949
workingDir "${nativeRootOutputDir}"
5050
commandLine "mkdir", "-p", "libs"
@@ -113,17 +113,19 @@ def gitClean(directory) {
113113
}
114114
}
115115

116-
def executeNdkBuild(outputDir, androidMkDirectory, applicationMkFile, cflags) {
116+
def executeNdkBuild(outputDir, androidMkDirectory, applicationMkFile,
117+
cflags, otherSqlcipherCFlags) {
117118
logger.info "Executing NDK build command"
118119
exec {
119120
def outputDirectory = "NDK_LIBS_OUT=${outputDir}"
120121
def applicationFile = "NDK_APPLICATION_MK=${applicationMkFile}"
121122
def environmentVariables = ["SQLCIPHER_CFLAGS": "${cflags}",
122123
"OPENSSL_DIR": "${opensslDir}",
123124
"SQLCIPHER_DIR": "${sqlcipherDir}",
125+
"SQLCIPHER_OTHER_CFLAGS" : "${otherSqlcipherCFlags}",
124126
"ANDROID_NATIVE_ROOT_DIR": "${androidNativeRootDir}"]
125127
environment(environmentVariables)
126-
commandLine "ndk-build",
128+
commandLine "ndk-build", "${ndkBuildType}",
127129
"--environment-overrides", outputDirectory,
128130
"-C", androidMkDirectory, applicationFile
129131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
44
LOCAL_PATH := $(MY_PATH)
55

66
SQLCIPHER_SRC := $(SQLCIPHER_DIR)/sqlite3.c
7-
LOCAL_CFLAGS += $(SQLCIPHER_CFLAGS) -DLOG_NDEBUG $(SQLCIPHER_OTHER_CFLAGS)
7+
LOCAL_CFLAGS += $(SQLCIPHER_CFLAGS) $(SQLCIPHER_OTHER_CFLAGS)
88
LOCAL_C_INCLUDES := $(SQLCIPHER_DIR) $(LOCAL_PATH)
99
LOCAL_LDLIBS := -llog -latomic
1010
LOCAL_LDFLAGS += -L$(ANDROID_NATIVE_ROOT_DIR)/$(TARGET_ARCH_ABI) -fuse-ld=bfd

android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteCursor.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package net.sqlcipher.database;
1818

1919
import net.sqlcipher.AbstractWindowedCursor;
20+
import net.sqlcipher.BuildConfig;
2021
import net.sqlcipher.CursorWindow;
2122
import net.sqlcipher.SQLException;
2223

@@ -252,7 +253,7 @@ public SQLiteCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
252253
for (int i = 0; i < columnCount; i++) {
253254
String columnName = mQuery.columnNameLocked(i);
254255
mColumns[i] = columnName;
255-
if (Config.LOGV) {
256+
if(BuildConfig.DEBUG){
256257
Log.v("DatabaseWindow", "mColumns[" + i + "] is "
257258
+ mColumns[i]);
258259
}
@@ -316,8 +317,10 @@ private void fillWindow (int requiredPos) {
316317
}
317318
mWindow.setStartPosition(startPos);
318319
mWindow.setRequiredPosition(requiredPos);
319-
Log.v(TAG, String.format("Filling cursor window with start position:%d required position:%d",
320-
startPos, requiredPos));
320+
if(BuildConfig.DEBUG){
321+
Log.v(TAG, String.format("Filling cursor window with start position:%d required position:%d",
322+
startPos, requiredPos));
323+
}
321324
mCount = mQuery.fillWindow(mWindow, mInitialRead, 0);
322325
if(mCursorWindowCapacity == 0) {
323326
mCursorWindowCapacity = mWindow.getNumRows();
@@ -347,8 +350,10 @@ public int getColumnIndex(String columnName) {
347350
final int periodIndex = columnName.lastIndexOf('.');
348351
if (periodIndex != -1) {
349352
Exception e = new Exception();
350-
Log.e(TAG, "requesting column name with table name -- " + columnName, e);
351-
columnName = columnName.substring(periodIndex + 1);
353+
if(BuildConfig.DEBUG){
354+
Log.e(TAG, "requesting column name with table name -- " + columnName, e);
355+
columnName = columnName.substring(periodIndex + 1);
356+
}
352357
}
353358

354359
Integer i = mColumnNameMap.get(columnName);
@@ -369,10 +374,12 @@ public boolean deleteRow() {
369374

370375
// Only allow deletes if there is an ID column, and the ID has been read from it
371376
if (mRowIdColumnIndex == -1 || mCurrentRowID == null) {
377+
if(BuildConfig.DEBUG){
372378
Log.e(TAG,
373-
"Could not delete row because either the row ID column is not available or it" +
374-
"has not been read.");
375-
return false;
379+
"Could not delete row because either the row ID column is not available or it" +
380+
"has not been read.");
381+
}
382+
return false;
376383
}
377384

378385
boolean success;
@@ -436,9 +443,11 @@ public boolean supportsUpdates() {
436443
public boolean commitUpdates(Map<? extends Long,
437444
? extends Map<String, Object>> additionalValues) {
438445
if (!supportsUpdates()) {
446+
if(BuildConfig.DEBUG){
439447
Log.e(TAG, "commitUpdates not supported on this cursor, did you "
440-
+ "include the _id column?");
441-
return false;
448+
+ "include the _id column?");
449+
}
450+
return false;
442451
}
443452

444453
/*
@@ -521,13 +530,13 @@ public boolean commitUpdates(Map<? extends Long,
521530
}
522531

523532
private void deactivateCommon() {
524-
if (Config.LOGV) Log.v(TAG, "<<< Releasing cursor " + this);
533+
if(BuildConfig.DEBUG) Log.v(TAG, "<<< Releasing cursor " + this);
525534
mCursorState = 0;
526535
if (mWindow != null) {
527536
mWindow.close();
528537
mWindow = null;
529538
}
530-
if (Config.LOGV) Log.v("DatabaseWindow", "closing window in release()");
539+
if(BuildConfig.DEBUG) Log.v("DatabaseWindow", "closing window in release()");
531540
}
532541

533542
@Override
@@ -578,15 +587,15 @@ public boolean requery() {
578587
mDatabase.unlock();
579588
}
580589

581-
if (Config.LOGV) {
582-
Log.v("DatabaseWindow", "closing window in requery()");
583-
Log.v(TAG, "--- Requery()ed cursor " + this + ": " + mQuery);
590+
if(BuildConfig.DEBUG){
591+
Log.v("DatabaseWindow", "closing window in requery()");
592+
Log.v(TAG, "--- Requery()ed cursor " + this + ": " + mQuery);
584593
}
585594

586595
boolean result = super.requery();
587-
if (Config.LOGV) {
588-
long timeEnd = System.currentTimeMillis();
589-
Log.v(TAG, "requery (" + (timeEnd - timeStart) + " ms): " + mDriver.toString());
596+
if(BuildConfig.DEBUG){
597+
long timeEnd = System.currentTimeMillis();
598+
Log.v(TAG, "requery (" + (timeEnd - timeStart) + " ms): " + mDriver.toString());
590599
}
591600
return result;
592601
}
@@ -622,16 +631,18 @@ protected void finalize() {
622631
// if the cursor hasn't been closed yet, close it first
623632
if (mWindow != null) {
624633
int len = mQuery.mSql.length();
625-
Log.e(TAG, "Finalizing a Cursor that has not been deactivated or closed. " +
634+
if(BuildConfig.DEBUG){
635+
Log.e(TAG, "Finalizing a Cursor that has not been deactivated or closed. " +
626636
"database = " + mDatabase.getPath() + ", table = " + mEditTable +
627637
", query = " + mQuery.mSql.substring(0, (len > 100) ? 100 : len),
628638
mStackTrace);
639+
}
629640
close();
630641
SQLiteDebug.notifyActiveCursorFinalized();
631642
} else {
632-
if (Config.LOGV) {
633-
Log.v(TAG, "Finalizing cursor on database = " + mDatabase.getPath() +
634-
", table = " + mEditTable + ", query = " + mQuery.mSql);
643+
if(BuildConfig.DEBUG) {
644+
Log.v(TAG, "Finalizing cursor on database = " + mDatabase.getPath() +
645+
", table = " + mEditTable + ", query = " + mQuery.mSql);
635646
}
636647
}
637648
} finally {
@@ -665,8 +676,10 @@ public void fillWindow(int requiredPos, android.database.CursorWindow window) {
665676
}
666677
mWindow.setStartPosition(startPos);
667678
mWindow.setRequiredPosition(requiredPos);
668-
Log.v(TAG, String.format("Filling cursor window with start position:%d required position:%d",
669-
startPos, requiredPos));
679+
if(BuildConfig.DEBUG) {
680+
Log.v(TAG, String.format("Filling cursor window with start position:%d required position:%d",
681+
startPos, requiredPos));
682+
}
670683
mCount = mQuery.fillWindow(mWindow, mInitialRead, 0);
671684
if(mCursorWindowCapacity == 0) {
672685
mCursorWindowCapacity = mWindow.getNumRows();

0 commit comments

Comments
 (0)