MOD: trying to get the library (wolfssl-jni.aar, wolfssl-lib.aar) to work with test application

This commit is contained in:
JohnE 2019-02-18 22:36:16 -08:00
parent fe13b8202b
commit 17059b1f03
7 changed files with 86 additions and 8 deletions

View File

@ -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"
// }
// }

View File

@ -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");
}
}

View File

@ -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)

View File

@ -17,3 +17,10 @@ ISSUES
NOTES
=====
* Debug Android binaries:
- https://resources.infosecinstitute.com/guide-debugging-android-binaries/

View File

@ -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 ..

View File

@ -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() {

View File

@ -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