diff --git a/.gitignore b/.gitignore index 96d0ddf..2c5e801 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build/ *.swp android/libs/ android/obj/ +cmake_build diff --git a/CMakeLists.txt b/CMakeLists.txt index afa94f0..761dbc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ elseif(APPLE) target_link_libraries(xg ${CFLIB}) add_definitions(-DGUID_CFUUID) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") +elseif(ANDROID) + target_compile_definitions(xg PRIVATE GUID_ANDROID) else() find_package(Libuuid REQUIRED) if (NOT LIBUUID_FOUND) diff --git a/Guid.cpp b/Guid.cpp index ca0c6be..98c77c3 100644 --- a/Guid.cpp +++ b/Guid.cpp @@ -39,6 +39,7 @@ THE SOFTWARE. #ifdef GUID_ANDROID #include +#include #endif BEGIN_XG_NAMESPACE @@ -50,13 +51,16 @@ AndroidGuidInfo AndroidGuidInfo::fromJniEnv(JNIEnv *env) { AndroidGuidInfo info; info.env = env; - info.uuidClass = env->FindClass("java/util/UUID"); + auto localUuidClass = env->FindClass("java/util/UUID"); + info.uuidClass = (jclass)env->NewGlobalRef(localUuidClass); + env->DeleteLocalRef(localUuidClass); info.newGuidMethod = env->GetStaticMethodID( info.uuidClass, "randomUUID", "()Ljava/util/UUID;"); info.mostSignificantBitsMethod = env->GetMethodID( info.uuidClass, "getMostSignificantBits", "()J"); info.leastSignificantBitsMethod = env->GetMethodID( info.uuidClass, "getLeastSignificantBits", "()J"); + info.initThreadId = std::this_thread::get_id(); return info; } @@ -340,13 +344,15 @@ Guid newGuid() // android version that uses a call to a java api #ifdef GUID_ANDROID -Guid newGuid() +Guid newGuid(JNIEnv *env) { - jobject javaUuid = androidInfo.env->CallStaticObjectMethod( + assert(env != androidInfo.env || std::this_thread::get_id() == androidInfo.initThreadId); + + jobject javaUuid = env->CallStaticObjectMethod( androidInfo.uuidClass, androidInfo.newGuidMethod); - jlong mostSignificant = androidInfo.env->CallLongMethod(javaUuid, + jlong mostSignificant = env->CallLongMethod(javaUuid, androidInfo.mostSignificantBitsMethod); - jlong leastSignificant = androidInfo.env->CallLongMethod(javaUuid, + jlong leastSignificant = env->CallLongMethod(javaUuid, androidInfo.leastSignificantBitsMethod); std::array bytes = @@ -369,12 +375,18 @@ Guid newGuid() (unsigned char)((leastSignificant) & 0xFF) }; - androidInfo.env->DeleteLocalRef(javaUuid); + env->DeleteLocalRef(javaUuid); return bytes; } + +Guid newGuid() +{ + return newGuid(androidInfo.env); +} #endif + END_XG_NAMESPACE // Specialization for std::swap() -- diff --git a/Guid.hpp b/Guid.hpp index 28a1cea..7dd8cbd 100644 --- a/Guid.hpp +++ b/Guid.hpp @@ -25,6 +25,7 @@ THE SOFTWARE. #pragma once #ifdef GUID_ANDROID +#include #include #endif @@ -84,11 +85,15 @@ struct AndroidGuidInfo jmethodID newGuidMethod; jmethodID mostSignificantBitsMethod; jmethodID leastSignificantBitsMethod; + std::thread::id initThreadId; }; extern AndroidGuidInfo androidInfo; void initJni(JNIEnv *env); + +// overloading for multi-threaded calls +Guid newGuid(JNIEnv *env); #endif END_XG_NAMESPACE diff --git a/README.md b/README.md index 631da6b..815619b 100644 --- a/README.md +++ b/README.md @@ -207,8 +207,7 @@ following requirements: * Android emulator is already running (or you have physical device connected). * You're using bash. * adb is in your path. -* ndk-build and other ndk cross-compile tools are in your path. -* You have a jdk setup including `JAVA_HOME` environment variable. +* You have an Android sdk setup including `ANDROID_HOME` environment variable. ## License diff --git a/android.sh b/android.sh index 3309159..bb26e9a 100755 --- a/android.sh +++ b/android.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash +export LC_NUMERIC="en_US.UTF-8" + pushd android -ndk-build clean || { exit 1; } -ndk-build || { exit 1; } -ant debug || { exit 1; } +./gradlew clean assembleDebug adb uninstall ca.graemehill.crossguid.testapp || { exit 1; } -adb install bin/TestApp-debug.apk || { exit 1; } +adb install app/build/outputs/apk/debug/app-debug.apk || { exit 1; } adb shell am start -n ca.graemehill.crossguid.testapp/ca.graemehill.crossguid.testapp.MainActivity popd diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..0f6ca2d --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild +.idea diff --git a/android/app/.gitignore b/android/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/android/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/app/CMakeLists.txt b/android/app/CMakeLists.txt new file mode 100644 index 0000000..11da347 --- /dev/null +++ b/android/app/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.4.1) + +set(LIB_NAME crossguidtest) +set(XG_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +set(XG_TEST_DIR ${XG_DIR}/test) + +add_library(${LIB_NAME} SHARED src/main/cpp/jnitest.cpp ${XG_TEST_DIR}/Test.cpp) + +target_include_directories(${LIB_NAME} PRIVATE + ${XG_DIR} + ${XG_TEST_DIR}) + +target_compile_definitions(${LIB_NAME} PRIVATE GUID_ANDROID) + +set(XG_TESTS OFF CACHE BOOL "disable tests") +add_subdirectory(${XG_DIR} ${XG_DIR}/cmake_build) + +target_link_libraries(${LIB_NAME} xg) \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle new file mode 100644 index 0000000..e715d3a --- /dev/null +++ b/android/app/build.gradle @@ -0,0 +1,39 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "26.0.0" + defaultConfig { + applicationId "ca.graemehill.crossguid.testapp" + minSdkVersion 14 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + externalNativeBuild { + cmake { + cppFlags "-std=c++11 -frtti -fexceptions" + arguments "-DANDROID_TOOLCHAIN=clang" + } + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.0', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + implementation 'com.android.support:appcompat-v7:25.4.0' + testImplementation 'junit:junit:4.12' +} diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 0000000..98587be --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /usr/local/Cellar/android-sdk/24.4.1_1/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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/android/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml similarity index 57% rename from android/AndroidManifest.xml rename to android/app/src/main/AndroidManifest.xml index d530671..c1a1e86 100644 --- a/android/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,9 +1,13 @@ - - + package="ca.graemehill.crossguid.testapp"> + + diff --git a/android/app/src/main/cpp/jnitest.cpp b/android/app/src/main/cpp/jnitest.cpp new file mode 100644 index 0000000..e3bd57c --- /dev/null +++ b/android/app/src/main/cpp/jnitest.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +#include +#include "Guid.hpp" +#include "Test.hpp" + +JavaVM *&javaVM() { + static JavaVM *jvm; + return jvm; +} + +extern "C" +{ + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void * /* reserved */) { + javaVM() = jvm; + return JNI_VERSION_1_6; +} + +JNIEXPORT jstring JNICALL +Java_ca_graemehill_crossguid_testapp_MainActivity_test( + JNIEnv *env, jobject /*thiz*/) +{ + std::stringstream resultStream; + xg::initJni(env); + test(resultStream); + return env->NewStringUTF(resultStream.str().c_str()); +} + +JNIEXPORT jstring JNICALL +Java_ca_graemehill_crossguid_testapp_MainActivity_newGuid( + JNIEnv *env, jobject /*thiz*/) { + return env->NewStringUTF(xg::newGuid(env).str().c_str()); +} + +JNIEXPORT jstring JNICALL +Java_ca_graemehill_crossguid_testapp_MainActivity_createGuidFromNativeThread( + JNIEnv *env, jobject /*thiz*/) { + + // there is no promise<> in armeabi of ndk + // so ugly atomic_bool wait solution + std::atomic_bool ready { false }; + std::string guid; + + std::thread([&ready, &guid](){ + JNIEnv *threadEnv; + javaVM()->AttachCurrentThread(&threadEnv, NULL); + guid = xg::newGuid(threadEnv); + javaVM()->DetachCurrentThread(); + + ready = true; + }).detach(); + + while (!ready); + return env->NewStringUTF(guid.c_str()); +} + +} diff --git a/android/app/src/main/java/ca/graemehill/crossguid/testapp/MainActivity.java b/android/app/src/main/java/ca/graemehill/crossguid/testapp/MainActivity.java new file mode 100644 index 0000000..4a285a2 --- /dev/null +++ b/android/app/src/main/java/ca/graemehill/crossguid/testapp/MainActivity.java @@ -0,0 +1,64 @@ +package ca.graemehill.crossguid.testapp; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +import java.util.concurrent.CountDownLatch; + +public class MainActivity extends Activity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + final TextView textView = (TextView)findViewById(R.id.mainTextView); + textView.setText(test()); + + final TextView javaThreadView = (TextView)findViewById(R.id.javaThreadView); + javaThreadView.setText(createGuidFromJavaThread()); + + final TextView nativeThreadView = (TextView)findViewById(R.id.nativeThreadView); + nativeThreadView.setText(createGuidFromNativeThread()); + } + + public native String test(); + + private static class StringCapture { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public String createGuidFromJavaThread() { + final CountDownLatch created = new CountDownLatch(1); + final StringCapture result = new StringCapture(); + new Thread(new Runnable() { + @Override + public void run() { + result.setValue(newGuid()); + created.countDown(); + } + }).start(); + try { + created.await(); + } catch (InterruptedException e) { + return "Could not get value: " + e.getMessage(); + } + return result.getValue(); + } + + public native String newGuid(); + + public native String createGuidFromNativeThread(); + static { + System.loadLibrary("crossguidtest"); + } +} diff --git a/android/app/src/main/res/layout/main.xml b/android/app/src/main/res/layout/main.xml new file mode 100644 index 0000000..8ba850a --- /dev/null +++ b/android/app/src/main/res/layout/main.xml @@ -0,0 +1,35 @@ + + + + + + + + + + diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..5507303 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..8fab6a3 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..6bc7fcd Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..1eecc0e Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..ec87dce Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..05ca079 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..6f67f21 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..8bac0f2 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..0327e13 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..bacd3e7 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/android/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..4b0fb85 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,6 @@ + + TestApp + GUID created from Native Thread + GUID created from Java Thread + Test results + diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/android/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..82ff274 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,26 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + maven { url 'https://maven.google.com' } + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.0.0-alpha3' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + maven { url 'https://maven.google.com' } + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 0000000..69b4e93 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +android.enableAapt2=false diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..4714bbc --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Aug 03 09:39:40 MSK 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip diff --git a/android/gradlew b/android/gradlew new file mode 100755 index 0000000..4a99613 --- /dev/null +++ b/android/gradlew @@ -0,0 +1,161 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" +LC_NUMERIC="en_US.UTF-8" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/android/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/android/jni/Android.mk b/android/jni/Android.mk deleted file mode 100644 index db23683..0000000 --- a/android/jni/Android.mk +++ /dev/null @@ -1,12 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := crossguidtest -LOCAL_CFLAGS := -Wall -LOCAL_SRC_FILES := ../../Guid.cpp ../../test/Test.cpp jnitest.cpp -LOCAL_CPP_FLAGS := -std=c++14 -LOCAL_CPPFLAGS := -DGUID_ANDROID -Wno-c++11-extensions -Wno-missing-braces -LOCAL_LDLIBS := -latomic - -include $(BUILD_SHARED_LIBRARY) diff --git a/android/jni/Application.mk b/android/jni/Application.mk deleted file mode 100644 index 4691b86..0000000 --- a/android/jni/Application.mk +++ /dev/null @@ -1,4 +0,0 @@ -APP_STL := c++_static -NDK_TOOLCHAIN_VERSION := clang -LOCAL_CPP_FLAGS := -DGUID_ANDROID -APP_ABI := all diff --git a/android/jni/jnitest.cpp b/android/jni/jnitest.cpp deleted file mode 100644 index de8ec14..0000000 --- a/android/jni/jnitest.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include -#include -#include "../../test/Test.hpp" -#include "../../Guid.hpp" - -extern "C" -{ - jstring Java_ca_graemehill_crossguid_testapp_MainActivity_test( - JNIEnv *env, jobject thiz) - { - std::stringstream resultStream; - xg::initJni(env); - test(resultStream); - return env->NewStringUTF(resultStream.str().c_str()); - } -} diff --git a/android/res/drawable-hdpi/ic_launcher.png b/android/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 96a442e..0000000 Binary files a/android/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/android/res/drawable-ldpi/ic_launcher.png b/android/res/drawable-ldpi/ic_launcher.png deleted file mode 100644 index 9923872..0000000 Binary files a/android/res/drawable-ldpi/ic_launcher.png and /dev/null differ diff --git a/android/res/drawable-mdpi/ic_launcher.png b/android/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 359047d..0000000 Binary files a/android/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/android/res/drawable-xhdpi/ic_launcher.png b/android/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 71c6d76..0000000 Binary files a/android/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/android/res/layout/main.xml b/android/res/layout/main.xml deleted file mode 100644 index ad54562..0000000 --- a/android/res/layout/main.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml deleted file mode 100644 index 0be1647..0000000 --- a/android/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - MainActivity - diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/android/src/ca/graemehill/crossguid/testapp/MainActivity.java b/android/src/ca/graemehill/crossguid/testapp/MainActivity.java deleted file mode 100644 index 99d1701..0000000 --- a/android/src/ca/graemehill/crossguid/testapp/MainActivity.java +++ /dev/null @@ -1,24 +0,0 @@ -package ca.graemehill.crossguid.testapp; - -import android.app.Activity; -import android.os.Bundle; -import android.widget.TextView; -import java.util.UUID; - -public class MainActivity extends Activity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - final TextView textView = (TextView)findViewById(R.id.mainTextView); - textView.setText(test()); - } - - public native String test(); - - static { - System.loadLibrary("crossguidtest"); - } -}