From 1cbb584011e5cb0a65e3629b18c4a44e0fe36dd5 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sun, 17 Jun 2018 01:11:16 -0400 Subject: [PATCH] Android support for new native masterpassword-core. --- gradle/build.gradle | 4 +-- lib/libjson-c | 2 +- platform-android/build.gradle | 30 +++++++++++++++---- platform-independent/c/core/src/mpw-jni.c | 8 +++++ .../java/algorithm/build.gradle | 2 +- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/gradle/build.gradle b/gradle/build.gradle index aa8fce5e..d2e843e0 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -11,8 +11,8 @@ allprojects { } tasks.withType( FindBugs ) { reports { - xml.enabled false - html.enabled true + xml.enabled = false + html.enabled = true } } } diff --git a/lib/libjson-c b/lib/libjson-c index 3e5ad38a..e3752b58 160000 --- a/lib/libjson-c +++ b/lib/libjson-c @@ -1 +1 @@ -Subproject commit 3e5ad38a83a05b641cd84414a67a64992bf0e8c6 +Subproject commit e3752b58945d23895535857ed136a5185bad02ce diff --git a/platform-android/build.gradle b/platform-android/build.gradle index b2b84e08..80df5283 100644 --- a/platform-android/build.gradle +++ b/platform-android/build.gradle @@ -4,11 +4,6 @@ android { compileSdkVersion 25 buildToolsVersion '27.0.3' - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - defaultConfig { applicationId 'com.lyndir.masterpassword' minSdkVersion 19 @@ -16,6 +11,21 @@ android { versionCode 20501 versionName '2.5.1' } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + externalNativeBuild { + cmake { + path 'CMakeLists.txt' + } + } + sourceSets { + main { + jniLibs.srcDirs "$projectDir/../lib/libsodium/build-android~/out/lib", + "$projectDir/../lib/libjson-c/build-android~/out/lib" + } + } // release with: STORE_PW=$(mpw masterpassword.keystore) KEY_PW_ANDROID=$(mpw masterpassword-android) gradle masterpassword-android:assembleRelease signingConfigs { @@ -43,3 +53,13 @@ dependencies { implementation group: 'com.jakewharton', name: 'butterknife', version: '8.5.1' annotationProcessor group: 'com.jakewharton', name: 'butterknife-compiler', version: '8.5.1' } + +preBuild { + dependsOn task( type: Exec, 'buildLibSodium', { + commandLine "$projectDir/../lib/bin/build_libsodium-android" + } ) + dependsOn task( type: Exec, 'buildLibJson-c', { + commandLine "$projectDir/../lib/bin/build_libjson-c-android" + } ) +} + diff --git a/platform-independent/c/core/src/mpw-jni.c b/platform-independent/c/core/src/mpw-jni.c index 5c936e16..9e1017a8 100644 --- a/platform-independent/c/core/src/mpw-jni.c +++ b/platform-independent/c/core/src/mpw-jni.c @@ -6,6 +6,14 @@ // TODO: We may need to zero the jbytes safely. +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + JNIEnv* env; + if (vm->GetEnv(&env, JNI_VERSION_1_6) != JNI_OK) + return -1; + + return JNI_VERSION_1_6; +} + /* native int _masterKey(final String fullName, final byte[] masterPassword, final Version version) */ JNIEXPORT jbyteArray JNICALL Java_com_lyndir_masterpassword_impl_MPAlgorithmV0__1masterKey(JNIEnv *env, jobject obj, jstring fullName, jbyteArray masterPassword, jint algorithmVersion) { diff --git a/platform-independent/java/algorithm/build.gradle b/platform-independent/java/algorithm/build.gradle index dcbb3923..2c4677ce 100644 --- a/platform-independent/java/algorithm/build.gradle +++ b/platform-independent/java/algorithm/build.gradle @@ -16,7 +16,7 @@ dependencies { api group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' api group: 'com.google.code.findbugs', name: 'findbugs-annotations', version: '3.0.1' - lib project( path: ':masterpassword-core', configuration: 'default' ) + //lib project( path: ':masterpassword-core', configuration: 'default' ) } processResources {