From 17059b1f03b185b34c51ec6e7f5d6ece8f8dde21 Mon Sep 17 00:00:00 2001 From: JohnE Date: Mon, 18 Feb 2019 22:36:16 -0800 Subject: [PATCH] MOD: trying to get the library (wolfssl-jni.aar, wolfssl-lib.aar) to work with test application --- ccc-jni/build.gradle | 30 +++++++++++++++---- .../main/java/io/malloc/ccc/MainActivity.java | 27 +++++++++++++++++ docs/android_cplusplus.rst | 18 +++++++++++ docs/weekly_2019-02-11.rst | 7 +++++ init.sh | 2 +- .../com/wolfssl/wolfcrypt/WolfObject.java | 3 +- .../test/{AesTest.java.bak => AesTest.java} | 7 ++++- 7 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 ccc-jni/src/main/java/io/malloc/ccc/MainActivity.java create mode 100644 docs/android_cplusplus.rst rename wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/{AesTest.java.bak => AesTest.java} (98%) diff --git a/ccc-jni/build.gradle b/ccc-jni/build.gradle index 4cdb4bc..f1b58a5 100644 --- a/ccc-jni/build.gradle +++ b/ccc-jni/build.gradle @@ -1,4 +1,4 @@ -apply plugin: 'com.android.library' +apply plugin: 'com.android.application' android { compileSdkVersion 28 @@ -6,7 +6,7 @@ android { buildToolsVersion '28.0.3' defaultConfig { - // applicationId 'xyz.nc.android.wc' + applicationId 'io.malloc.ccc' minSdkVersion 23 targetSdkVersion 28 versionCode 1 @@ -15,12 +15,24 @@ android { externalNativeBuild { cmake { arguments '-DANDROID_PLATFORM=android-23', - '-DANDROID_TOOLCHAIN=clang' + '-DANDROID_TOOLCHAIN=clang', + '-DANDROID_STL=c++_static' } - } } - + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), + 'proguard-rules.pro' + } + } + sourceSets { + main { + // let gradle pack the shared library into apk + jniLibs.srcDirs = ['libs/wolfssl-jni'] + } + } externalNativeBuild { cmake { path 'CMakeLists.txt' @@ -47,3 +59,11 @@ task copyLibs(type: Copy) { dependencies { testImplementation 'junit:junit:4.12' } + +// tasks.whenTaskAdded { task -> +// if (task.name == 'externalNativeBuildRelease') { +// task.dependsOn ":gen-libs:externalNativeBuildRelease" +// } else if (task.name == 'externalNativeBuildDebug') { +// task.dependsOn ":gen-libs:externalNativeBuildDebug" +// } +// } diff --git a/ccc-jni/src/main/java/io/malloc/ccc/MainActivity.java b/ccc-jni/src/main/java/io/malloc/ccc/MainActivity.java new file mode 100644 index 0000000..0ec1dc6 --- /dev/null +++ b/ccc-jni/src/main/java/io/malloc/ccc/MainActivity.java @@ -0,0 +1,27 @@ +/* + + */ +package io.malloc.ccc; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.TextView; +/* + * Simple Java UI to trigger jni function. It is exactly same as Java code + * in hello-jni. + */ +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + TextView tv = new TextView(this); + tv.setText( stringFromJNI() ); + setContentView(tv); + } + public native String stringFromJNI(); + static { + System.loadLibrary("hello-libs"); + } + +} diff --git a/docs/android_cplusplus.rst b/docs/android_cplusplus.rst new file mode 100644 index 0000000..df0f45a --- /dev/null +++ b/docs/android_cplusplus.rst @@ -0,0 +1,18 @@ +=================== +Android C Plus Plus +=================== + + +Metadata +======== + +* C++ 17 support (libc++) +* LLVM libc++ is the C++ standard library (STL) + - https://libcxx.llvm.org/ +* libc++_shared.so libc++_static.a +* MUST be included in the APK (not part of the system libraries) + + + + + diff --git a/docs/weekly_2019-02-11.rst b/docs/weekly_2019-02-11.rst index cd4ab86..a27b4fb 100644 --- a/docs/weekly_2019-02-11.rst +++ b/docs/weekly_2019-02-11.rst @@ -17,3 +17,10 @@ ISSUES + +NOTES +===== + +* Debug Android binaries: + - https://resources.infosecinstitute.com/guide-debugging-android-binaries/ + diff --git a/init.sh b/init.sh index 1404d35..9ae60bb 100755 --- a/init.sh +++ b/init.sh @@ -6,7 +6,7 @@ WOLF_BRANCH='v3.10.0-stable' # checkout wolfssl -cd wolfssl +cd wolfssl-lib # this dot is the same as "source" of the file . get_wolfssl_src.sh $WOLF_BRANCH cd .. diff --git a/wolfssl-jni/src/main/java/com/wolfssl/wolfcrypt/WolfObject.java b/wolfssl-jni/src/main/java/com/wolfssl/wolfcrypt/WolfObject.java index 87792a3..45a5d29 100644 --- a/wolfssl-jni/src/main/java/com/wolfssl/wolfcrypt/WolfObject.java +++ b/wolfssl-jni/src/main/java/com/wolfssl/wolfcrypt/WolfObject.java @@ -31,7 +31,8 @@ package com.wolfssl.wolfcrypt; public class WolfObject { static { - System.loadLibrary("wolfcrypt-jni"); + // libwolfssl-jni.so + System.loadLibrary("wolfssl-jni"); } protected WolfObject() { diff --git a/wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java.bak b/wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java similarity index 98% rename from wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java.bak rename to wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java index e2742f9..232290f 100644 --- a/wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java.bak +++ b/wolfssl-jni/src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java @@ -47,11 +47,16 @@ public class AesTest { public static void checkAvailability() { try { new Aes(); - } catch (WolfCryptException e) { + } + catch (WolfCryptException e) { if (e.getError() == WolfCryptError.NOT_COMPILED_IN) System.out.println("Aes test skipped: " + e.getError()); Assume.assumeNoException(e); } + catch (UnsatisfiedLinkError e) { + System.out.println("Native code library failed to load.\n" + e.getError()); + Assume.assumeNoException(e); + } } @Test