From 5a6750337868f7c92baa65d2118ac7ecc84f6010 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 16 Apr 2019 11:36:36 +0200 Subject: JNI templates --- .../androidTest/kotlin/InstrumentedAkonoTests.kt | 21 ++++++++++ library/src/main/AndroidManifest.xml | 7 ++++ library/src/main/cpp/CMakeLists.txt | 15 +++++++ library/src/main/cpp/akono-jni.c | 47 ++++++++++++++++++++++ library/src/main/kotlin/akono/AkoniJni.kt | 11 +++++ library/src/main/kotlin/akono/Library.kt | 10 +++++ library/src/test/kotlin/akono/LibraryTest.kt | 16 ++++++++ 7 files changed, 127 insertions(+) create mode 100644 library/src/androidTest/kotlin/InstrumentedAkonoTests.kt create mode 100644 library/src/main/AndroidManifest.xml create mode 100644 library/src/main/cpp/CMakeLists.txt create mode 100644 library/src/main/cpp/akono-jni.c create mode 100644 library/src/main/kotlin/akono/AkoniJni.kt create mode 100644 library/src/main/kotlin/akono/Library.kt create mode 100644 library/src/test/kotlin/akono/LibraryTest.kt (limited to 'library/src') diff --git a/library/src/androidTest/kotlin/InstrumentedAkonoTests.kt b/library/src/androidTest/kotlin/InstrumentedAkonoTests.kt new file mode 100644 index 00000000..b5ea0111 --- /dev/null +++ b/library/src/androidTest/kotlin/InstrumentedAkonoTests.kt @@ -0,0 +1,21 @@ +package akono.test; + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.runner.RunWith +import org.junit.Test +import androidx.test.filters.SmallTest +import androidx.test.filters.LargeTest +import org.junit.Assert.assertTrue +import org.junit.Assert.assertEquals +import akono.AkonoJni + +// @RunWith is required only if you use a mix of JUnit3 and JUnit4. +@RunWith(AndroidJUnit4::class) +@LargeTest +public class InstrumentedAkonoTestOne { + @Test + fun myAkonoTest() { + val ajni: AkonoJni = AkonoJni() + assertEquals("foo", ajni.stringFromJNI()) + } +} diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml new file mode 100644 index 00000000..3a8d4915 --- /dev/null +++ b/library/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/library/src/main/cpp/CMakeLists.txt b/library/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..b2983d0b --- /dev/null +++ b/library/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.4.1) + +add_library(akono-jni SHARED + akono-jni.c) + +add_library(v8 STATIC IMPORTED) +set_target_properties(v8 PROPERTIES IMPORTED_LOCATION + ${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so) + + +# Include libraries needed for hello-jni lib +target_link_libraries(akono-jni + android + log) + diff --git a/library/src/main/cpp/akono-jni.c b/library/src/main/cpp/akono-jni.c new file mode 100644 index 00000000..49777431 --- /dev/null +++ b/library/src/main/cpp/akono-jni.c @@ -0,0 +1,47 @@ +#include +#include + +/* This is a trivial JNI example where we use a native method + * to return a new VM String. See the corresponding Java source + * file located at: + * + * hello-jni/app/src/main/java/com/example/hellojni/HelloJni.java + */ +JNIEXPORT jstring JNICALL +Java_akono_AkonoJni_stringFromJNI( JNIEnv* env, + jobject thiz ) +{ +#if defined(__arm__) + #if defined(__ARM_ARCH_7A__) + #if defined(__ARM_NEON__) + #if defined(__ARM_PCS_VFP) + #define ABI "armeabi-v7a/NEON (hard-float)" + #else + #define ABI "armeabi-v7a/NEON" + #endif + #else + #if defined(__ARM_PCS_VFP) + #define ABI "armeabi-v7a (hard-float)" + #else + #define ABI "armeabi-v7a" + #endif + #endif + #else + #define ABI "armeabi" + #endif +#elif defined(__i386__) +#define ABI "x86" +#elif defined(__x86_64__) +#define ABI "x86_64" +#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */ +#define ABI "mips64" +#elif defined(__mips__) +#define ABI "mips" +#elif defined(__aarch64__) +#define ABI "arm64-v8a" +#else +#define ABI "unknown" +#endif + + return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI " ABI "."); +} diff --git a/library/src/main/kotlin/akono/AkoniJni.kt b/library/src/main/kotlin/akono/AkoniJni.kt new file mode 100644 index 00000000..d3bc7a72 --- /dev/null +++ b/library/src/main/kotlin/akono/AkoniJni.kt @@ -0,0 +1,11 @@ +package akono; + +class AkonoJni { + external fun stringFromJNI(): String; + + companion object { + init { + System.loadLibrary("akono-jni") + } + } +} diff --git a/library/src/main/kotlin/akono/Library.kt b/library/src/main/kotlin/akono/Library.kt new file mode 100644 index 00000000..920648fd --- /dev/null +++ b/library/src/main/kotlin/akono/Library.kt @@ -0,0 +1,10 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package akono + +class Library { + fun someLibraryMethod(): Boolean { + return true + } +} diff --git a/library/src/test/kotlin/akono/LibraryTest.kt b/library/src/test/kotlin/akono/LibraryTest.kt new file mode 100644 index 00000000..1a16e7e6 --- /dev/null +++ b/library/src/test/kotlin/akono/LibraryTest.kt @@ -0,0 +1,16 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package akono + +import kotlin.test.Test +import kotlin.test.assertTrue +import kotlin.test.assertEquals + +import akono.AkonoJni + +class LibraryTest { + @Test fun testSomeLibraryMethod() { + assertTrue(true) + } +} -- cgit v1.2.3