diff --git a/.github/workflows/Android-CI.yml b/.github/workflows/Android-CI.yml new file mode 100644 index 00000000..b1a1eafc --- /dev/null +++ b/.github/workflows/Android-CI.yml @@ -0,0 +1,35 @@ +name: CI Android + +on: + push: + branches: + - master + pull_request: + branches: + - trust + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Env + run: env + - name: NDK search + run: find /usr/local/lib/android -iname ndk-build 2>/dev/null + - name: Search for ndk_locator_record.json before + run: find . -name ndk_locator_record.json 2>/dev/null + - name: Make init + run: make init + - name: Status + run: git status + - name: Build with Gradle + run: export ANDROID_NDK_HOME=/usr/local/lib/android/sdk/ndk-bundle && ./gradlew clean check android-database-sqlcipher:bundleReleaseAar -PdebugBuild=false --stacktrace + - name: Search for ndk_locator_record.json after + run: find . -name ndk_locator_record.json 2>/dev/null diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml new file mode 100644 index 00000000..f552c8dc --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -0,0 +1,10 @@ +name: "Validate Gradle Wrapper" +on: [push] + +jobs: + validation: + name: "Validation" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: gradle/wrapper-validation-action@v1 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..b1f86923 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,58 @@ +language: android + +branches: + only: + - master + - trust + +sudo: true + +jdk: + - oraclejdk8 + +dist : trusty # otherwise you run into /home/travis/.travis/functions: line 104: sdkmanager: command not found + +env: + - TERM=dumb + +global: + - PATH=$ANDROID_HOME:$ANDROID_HOME/platform-tools:$PATH + +android: + components: + - tools + - platform-tools + - android-28 + +install: + - echo $ANDROID_HOME # We assume this is correctly set when setting path + - sdkmanager --list || true # Look at the packages + - echo yes | sdkmanager "tools" # Ensure tools is updated + - echo y | sdkmanager 'ndk-bundle' 1>/dev/null + - echo y | sdkmanager 'cmake;3.6.4111459' 1>/dev/null + - echo y | sdkmanager 'lldb;3.0' 1>/dev/null + +before_script: + - wget --quiet https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip + - unzip -q android-ndk-r20b-linux-x86_64.zip + - export ANDROID_NDK_ROOT=`pwd`/android-ndk-r20b + - export ANDROID_NDK_HOME=$ANDROID_NDK_ROOT + - PATH=${PATH}:$ANDROID_NDK_ROOT + +script: + - make init + - git status + - ./gradlew clean check android-database-sqlcipher:bundleReleaseAar -PdebugBuild=false --stacktrace + +after_success: + # try to upload version and ignore any errors + - ./gradlew bintrayUpload || echo "Version seems to exists already" + +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ + +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ diff --git a/Makefile b/Makefile index 151f9eeb..b7806214 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ format: $(GRADLE) editorconfigFormat build-debug: check - $(GRADLE) android-database-sqlcipher:bundleDebugAar \ - -PdebugBuild=true + TERM=dumb $(GRADLE) android-database-sqlcipher:bundleDebugAar \ + -PdebugBuild=true --stacktrace build-release: $(GRADLE) android-database-sqlcipher:bundleReleaseAar \ diff --git a/android-database-sqlcipher/build.gradle b/android-database-sqlcipher/build.gradle index 7ed66afd..eb98c38e 100644 --- a/android-database-sqlcipher/build.gradle +++ b/android-database-sqlcipher/build.gradle @@ -1,7 +1,32 @@ apply plugin: "com.android.library" apply plugin: "org.ec4j.editorconfig" apply from: "native.gradle" -apply from: "maven.gradle" +apply plugin: 'com.github.dcendents.android-maven' +apply plugin: 'com.jfrog.bintray' + +ext { + bintrayRepo = 'maven' + bintrayName = 'android-database-sqlcipher' + + publishedGroupId = 'info.hannes.android' + libraryName = 'database-sqlcipher' + artifact = 'android-database-sqlcipher' + + libraryDescription = 'Android SQLite API based on SQLCipher' + + siteUrl = 'https://github.com/hannesa2/android-database-sqlcipher' + gitUrl = 'https://github.com/hannesa2/android-database-sqlcipher.git' + + libraryVersion = '4.4.2.0' + + developerId = 'hannesa2' + developerName = 'Hannes Achleitner' + developerEmail = 'hannes.software@gmx.at' + + licenseName = 'The Apache Software License, Version 2.0' + licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + allLicenses = ["Apache-2.0"] +} android { @@ -14,6 +39,15 @@ android { versionCode 1 versionName "${clientVersionNumber}" archivesBaseName = "${archivesBaseName}-${versionName}" + + + buildConfigField "String", "GIT_COMMIT_SHA1", "\"" + getLatestGitHash() + "\"" + buildConfigField "String", "GIT_COMMIT_URL", "\"" + getGitCommitUrl() + "\"" + buildConfigField "String", "GIT_REPO_URL", "\"" + getGitRepoUrl() + "\"" + buildConfigField "String", "GIT_TAG_URL", "\"" + getGitRepoUrl() + "/tags" + "\"" + buildConfigField "String", "TRAVIS_BUILD_ID", "\"" + getTravisBuildId() + "\"" + buildConfigField "String", "TRAVIS_BUILD_URL", "\"" + getTravisBuildUrl() + "\"" + buildConfigField "String", "JITPACK_BUILD_URL", "\"" + getJitpackBuildUrl() + "\"" } editorconfig { @@ -38,7 +72,7 @@ android { } dependencies { - implementation "androidx.sqlite:sqlite:2.0.1" + implementation "androidx.sqlite:sqlite:2.1.0" } editorconfig { @@ -54,3 +88,66 @@ android { preBuild.dependsOn([buildOpenSSL, buildAmalgamation, copyAmalgamation, buildNative]) buildNative.mustRunAfter(copyAmalgamation) } + +private static def getGitCommitCount() { + try { + return 'git rev-list --first-parent --count HEAD'.execute().text.trim() as Integer + } + catch (ignored) { + return 0 + } +} + +private static def getLatestGitHash() { + try { + return 'git rev-parse --short HEAD'.execute().text.trim() + } + catch (ignored) { + return null + } +} + +static def getCreateTime() { + def process = "date +%F".execute() + return process.text.toString().trim() +} + +static private def getVersionName() { + println "Version: " + getCreateTime() + "." + getGitCommitCount() + "-" + getLatestGitHash() + return getCreateTime() + "." + getGitCommitCount() + "-" + getLatestGitHash() +} + +static def getGitCommitUrl() { + return getGitRepoUrl() + "/commit/" + getLatestGitHash() +} + +static def getGitRepoUrl() { + def process = "git remote get-url origin --push".execute() + return process.text.toString().replace(".git", "").trim() +} + +static def getTravisBuildId() { + return System.getenv("TRAVIS_BUILD_ID") +} + +static def getTravisBuildUrl() { + if (System.getenv("CI_SERVER")) { + return getTravisBuildId() + } else { + println "buildID:" + "https://travis-ci.org/" + System.getenv("TRAVIS_REPO_SLUG") + "/builds/" + getTravisBuildId() + println "TRAVIS_BUILD_DIR:" + System.getenv("TRAVIS_BUILD_DIR") + println "TRAVIS_BUILD_ID:" + System.getenv("TRAVIS_BUILD_ID") + println "TRAVIS_BUILD_NUMBER:" + System.getenv("TRAVIS_BUILD_NUMBER") + println "TRAVIS_COMMIT:" + System.getenv("TRAVIS_COMMIT") + println "TRAVIS_COMMIT_MESSAGE:" + System.getenv("TRAVIS_COMMIT_MESSAGE") + println "TRAVIS_COMMIT_RANGE:" + System.getenv("TRAVIS_COMMIT_RANGE") + println "TRAVIS_JOB_ID:" + System.getenv("TRAVIS_JOB_ID") + println "TRAVIS_JOB_NUMBER:" + System.getenv("TRAVIS_JOB_NUMBER") + return "https://travis-ci.org/" + System.getenv("TRAVIS_REPO_SLUG") + "/builds/" + getTravisBuildId() + } +} + +static def getJitpackBuildUrl() { + def process = ("git describe --exact-match " + getLatestGitHash() + " 2>/dev/null | echo noTag").execute() + return getGitRepoUrl().replace("https://github.com", "https://jitpack.io/com/github") + "/" + process.text.toString().replace("noTag", "").trim() + "/build.log" +} diff --git a/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java b/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java index 8bf94945..f0855a5e 100644 --- a/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java +++ b/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java @@ -2620,7 +2620,7 @@ public void run() { rekey(password); } shouldCloseConnection = false; - } else { + } else if (!ex.getMessage().contains("not an error")) { throw ex; } if(keyMaterial != null && keyMaterial.length > 0) { @@ -2674,7 +2674,7 @@ private void keyDatabase(SQLiteDatabaseHook databaseHook, Runnable keyOperation) } } catch (RuntimeException e) { if(BuildConfig.DEBUG){ - Log.e(TAG, e.getMessage(), e); + Log.w(TAG, e.getMessage(), e); } throw e; } diff --git a/build.gradle b/build.gradle index 9123502a..c957c3ec 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,10 @@ buildscript { } } dependencies { - classpath "com.android.tools.build:gradle:3.4.1" + classpath "com.android.tools.build:gradle:4.1.2" classpath "gradle.plugin.org.ec4j.gradle:editorconfig-gradle-plugin:0.0.3" + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' } } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..dbb7bf70 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +android.enableJetifier=true +android.useAndroidX=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7a3265ee..e708b1c0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffb59778..28ff446a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip diff --git a/gradlew b/gradlew index cccdd3d5..4f906e0c 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,19 +156,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f9553162..107acd32 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/jcenter.gradle b/jcenter.gradle new file mode 100644 index 00000000..04763295 --- /dev/null +++ b/jcenter.gradle @@ -0,0 +1,79 @@ +group = publishedGroupId +version = libraryVersion + +install { + repositories.mavenInstaller { + pom.project { + packaging 'aar' + groupId publishedGroupId + artifactId artifact + + name libraryName + description libraryDescription + url siteUrl + + licenses { + license { + name licenseName + url licenseUrl + } + } + developers { + developer { + id developerId + name developerName + email developerEmail + } + } + scm { + connection gitUrl + developerConnection gitUrl + url siteUrl + } + } + } +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.srcDirs +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) +} + +// Javadoc doesn't work in this repo +//task javadocJar(type: Jar, dependsOn: javadoc) { +// classifier = 'javadoc' +// from javadoc.destinationDir +//} + +artifacts { +// archives javadocJar + archives sourcesJar +} + +bintray { + user = System.getenv('BINTRAY_USER') + key = System.getenv('BINTRAY_KEY') + + configurations = ['archives'] + pkg { + repo = bintrayRepo + name = bintrayName + desc = libraryDescription + websiteUrl = siteUrl + vcsUrl = gitUrl + licenses = allLicenses + dryRun = false + publish = true + override = false + publicDownloadNumbers = true + version { + desc = libraryDescription + released = new Date() + } + } +} diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 00000000..de23b2a1 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,3 @@ +env: + ANDROID_NDK_ROOT : `pwd`/android-ndk-r15c + PATH : ${PATH}:$ANDROID_NDK_ROOT \ No newline at end of file