From 9aefabf76b30e1e132103b15499f010c9aa2d4b8 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Mon, 14 Jan 2019 12:03:18 +0800 Subject: [PATCH] feat(android): add libmynteye to android --- wrappers/android/mynteye/app/build.gradle | 5 ++ .../mynteye/gradle/dependencies.gradle | 3 + .../android/mynteye/libmynteye/.gitignore | 1 + .../android/mynteye/libmynteye/build.gradle | 46 +++++++++++++ .../mynteye/libmynteye/proguard-rules.pro | 21 ++++++ .../mynteye/ExampleInstrumentedTest.java | 26 +++++++ .../libmynteye/src/main/AndroidManifest.xml | 2 + .../libmynteye/src/main/cpp/CMakeLists.txt | 67 +++++++++++++++++++ .../slightech/mynteye/ExampleUnitTest.java | 17 +++++ wrappers/android/mynteye/settings.gradle | 2 +- 10 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 wrappers/android/mynteye/libmynteye/.gitignore create mode 100644 wrappers/android/mynteye/libmynteye/build.gradle create mode 100644 wrappers/android/mynteye/libmynteye/proguard-rules.pro create mode 100644 wrappers/android/mynteye/libmynteye/src/androidTest/java/com/slightech/mynteye/ExampleInstrumentedTest.java create mode 100644 wrappers/android/mynteye/libmynteye/src/main/AndroidManifest.xml create mode 100644 wrappers/android/mynteye/libmynteye/src/main/cpp/CMakeLists.txt create mode 100644 wrappers/android/mynteye/libmynteye/src/test/java/com/slightech/mynteye/ExampleUnitTest.java diff --git a/wrappers/android/mynteye/app/build.gradle b/wrappers/android/mynteye/app/build.gradle index cc86012..229eac5 100644 --- a/wrappers/android/mynteye/app/build.gradle +++ b/wrappers/android/mynteye/app/build.gradle @@ -9,6 +9,9 @@ android { versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + ndk { + abiFilters xabis + } } buildTypes { release { @@ -24,6 +27,8 @@ dependencies { implementation xdeps.support.appcompat implementation xdeps.support.constraint + implementation project(':libmynteye') + testImplementation xdeps.junit androidTestImplementation xdeps.support.test.runner androidTestImplementation xdeps.support.test.espresso diff --git a/wrappers/android/mynteye/gradle/dependencies.gradle b/wrappers/android/mynteye/gradle/dependencies.gradle index da2d862..c4d7278 100644 --- a/wrappers/android/mynteye/gradle/dependencies.gradle +++ b/wrappers/android/mynteye/gradle/dependencies.gradle @@ -41,4 +41,7 @@ ext { // JUnit4: https://github.com/junit-team/junit4 'junit': 'junit:junit:4.12', ] + + xabis = ['arm64-v8a', 'armeabi-v7a'] as String[] + //xabis = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] as String[] } diff --git a/wrappers/android/mynteye/libmynteye/.gitignore b/wrappers/android/mynteye/libmynteye/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/.gitignore @@ -0,0 +1 @@ +/build diff --git a/wrappers/android/mynteye/libmynteye/build.gradle b/wrappers/android/mynteye/libmynteye/build.gradle new file mode 100644 index 0000000..97f0e29 --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/build.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion xversions.compileSdk + + defaultConfig { + minSdkVersion xversions.minSdk + targetSdkVersion xversions.targetSdk + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + externalNativeBuild { + // https://developer.android.com/ndk/guides/cmake + cmake { + cppFlags "-std=c++11 -frtti -fexceptions" + } + } + + ndk { + abiFilters xabis + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + externalNativeBuild { + cmake { + path "src/main/cpp/CMakeLists.txt" + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + testImplementation xdeps.junit + androidTestImplementation xdeps.support.test.runner + androidTestImplementation xdeps.support.test.espresso +} diff --git a/wrappers/android/mynteye/libmynteye/proguard-rules.pro b/wrappers/android/mynteye/libmynteye/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/wrappers/android/mynteye/libmynteye/src/androidTest/java/com/slightech/mynteye/ExampleInstrumentedTest.java b/wrappers/android/mynteye/libmynteye/src/androidTest/java/com/slightech/mynteye/ExampleInstrumentedTest.java new file mode 100644 index 0000000..2b84b62 --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/src/androidTest/java/com/slightech/mynteye/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.slightech.mynteye; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.slightech.mynteye.test", appContext.getPackageName()); + } +} diff --git a/wrappers/android/mynteye/libmynteye/src/main/AndroidManifest.xml b/wrappers/android/mynteye/libmynteye/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7db87f0 --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/wrappers/android/mynteye/libmynteye/src/main/cpp/CMakeLists.txt b/wrappers/android/mynteye/libmynteye/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000..104bdf3 --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/src/main/cpp/CMakeLists.txt @@ -0,0 +1,67 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.4.1) + +get_filename_component(MYNTETE_ROOT "${PROJECT_SOURCE_DIR}/../../../../../../.." ABSOLUTE) +message(STATUS "MYNTETE_ROOT: ${MYNTETE_ROOT}") + +set(MYNTEYE_NAME "mynteye") + +set(MYNTEYE_NAMESPACE "${MYNTEYE_NAME}") +message(STATUS "Namespace: ${MYNTEYE_NAMESPACE}") + +configure_file( + ${MYNTETE_ROOT}/include/mynteye/mynteye.h.in + include/mynteye/mynteye.h @ONLY +) + +## libs + +find_library(log-lib log) + +## targets + +# libmynteye + +add_definitions(-DMYNTEYE_EXPORTS) + +set(MYNTEYE_SRCS + ${MYNTETE_ROOT}/src/mynteye/uvc/linux/uvc-v4l2.cc + ${MYNTETE_ROOT}/src/mynteye/types.cc + ${MYNTETE_ROOT}/src/mynteye/util/files.cc + ${MYNTETE_ROOT}/src/mynteye/util/strings.cc + ${MYNTETE_ROOT}/src/mynteye/device/channel/bytes.cc + ${MYNTETE_ROOT}/src/mynteye/device/channel/channels.cc + ${MYNTETE_ROOT}/src/mynteye/device/channel/file_channel.cc + ${MYNTETE_ROOT}/src/mynteye/device/config.cc + ${MYNTETE_ROOT}/src/mynteye/device/context.cc + ${MYNTETE_ROOT}/src/mynteye/device/device.cc + ${MYNTETE_ROOT}/src/mynteye/device/motions.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard/channels_adapter_s.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard/device_s.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard/streams_adapter_s.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard2/channels_adapter_s2.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard2/device_s2.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard2/streams_adapter_s2.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard2/channels_adapter_s210a.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard2/device_s210a.cc + ${MYNTETE_ROOT}/src/mynteye/device/standard2/streams_adapter_s210a.cc + ${MYNTETE_ROOT}/src/mynteye/device/streams.cc + ${MYNTETE_ROOT}/src/mynteye/device/types.cc + ${MYNTETE_ROOT}/src/mynteye/device/utils.cc +) + +list(APPEND MYNTEYE_SRCS ${MYNTETE_ROOT}/src/mynteye/miniglog.cc) + +add_library(${MYNTEYE_NAME} SHARED ${MYNTEYE_SRCS}) +target_link_libraries(${MYNTEYE_NAME} ${log-lib}) + +target_include_directories(${MYNTEYE_NAME} PUBLIC + "$" + "$" + "$" + "$" +) diff --git a/wrappers/android/mynteye/libmynteye/src/test/java/com/slightech/mynteye/ExampleUnitTest.java b/wrappers/android/mynteye/libmynteye/src/test/java/com/slightech/mynteye/ExampleUnitTest.java new file mode 100644 index 0000000..6d3ba42 --- /dev/null +++ b/wrappers/android/mynteye/libmynteye/src/test/java/com/slightech/mynteye/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.slightech.mynteye; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/wrappers/android/mynteye/settings.gradle b/wrappers/android/mynteye/settings.gradle index e7b4def..f04decd 100644 --- a/wrappers/android/mynteye/settings.gradle +++ b/wrappers/android/mynteye/settings.gradle @@ -1 +1 @@ -include ':app' +include ':app', ':libmynteye'