diff --git a/AS3/app/CMakeLists.txt b/AS3/app/CMakeLists.txt index b6b6b16..4d70ffc 100644 --- a/AS3/app/CMakeLists.txt +++ b/AS3/app/CMakeLists.txt @@ -36,17 +36,6 @@ add_library( # Sets the name of the library. # Provides the list of files to compile. ${SOURCE_FILES} ) -# Searches for a specified prebuilt library and stores the path as a -# variable. Because CMake includes system libraries in the search path by -# default, you only need to specify the name of the public NDK library -# you want to add. CMake verifies that the library exists before -# completing its build. -find_library( # Sets the name of the path variable. - log-lib - - # Specifies the name of the NDK library that you want CMake to locate. - log ) - # Fail the build if SWIG is not found - Ensure SWIG is installed and on the system path # TODO: Does this run for EACH architecture? find_package(SWIG REQUIRED) @@ -56,7 +45,7 @@ include(${SWIG_USE_FILE}) file(REMOVE_RECURSE ${JAVA_GEN_DIR}) # Ensure file recognized as C++ (otherwise, exported as C file) -set_property(SOURCE src/main/cpp/SeePlusPlus.i PROPERTY CPLUSPLUS ON) +set_property(SOURCE ${SWIG_I_FILE} PROPERTY CPLUSPLUS ON) # Setup SWIG flags and locations set(CMAKE_SWIG_FLAGS -c++ -package ${JAVA_GEN_PACKAGE}) @@ -66,12 +55,44 @@ set(CMAKE_SWIG_OUTDIR ${JAVA_GEN_DIR}) swig_add_module(SeePlusPlus_Wrapper java ${SWIG_I_FILE}) swig_link_libraries(SeePlusPlus_Wrapper SeePlusPlus) -# Specifies libraries CMake should link to your target library. You -# can link multiple libraries, such as libraries you define in this -# build script, prebuilt third-party libraries, or system libraries. -target_link_libraries( # Specifies the target library. - SeePlusPlus +# Need to create the .dylib and .jnilib files in order to run JUnit tests +if (APPLE) + + # Ensure jni.h is found + find_package(JNI REQUIRED) + include_directories(${JAVA_INCLUDE_PATH}) + + #find_package(SWIG REQUIRED) + #include(${SWIG_USE_FILE}) + #set_property(SOURCE ${SWIG_I_FILE} PROPERTY CPLUSPLUS ON) + + #set(CMAKE_SWIG_FLAGS -c++ -package com.sureshjoshi.core) + #set(CMAKE_SWIG_OUTDIR ${Project_SOURCE_DIR}/src/main/cpp/wrapper) + + #swig_add_library(SeePlusPlus_Wrapper LANGUAGE java SOURCES ${SWIG_I_FILE}) + #swig_link_libraries(SeePlusPlus_Wrapper SeePlusPlus) + +else() + + # Searches for a specified prebuilt library and stores the path as a + # variable. Because CMake includes system libraries in the search path by + # default, you only need to specify the name of the public NDK library + # you want to add. CMake verifies that the library exists before + # completing its build. + find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that you want CMake to locate. + log ) + + # Specifies libraries CMake should link to your target library. You + # can link multiple libraries, such as libraries you define in this + # build script, prebuilt third-party libraries, or system libraries. + target_link_libraries( # Specifies the target library. + SeePlusPlus + + # Links the target library to the log library + # included in the NDK. + ${log-lib} ) - # Links the target library to the log library - # included in the NDK. - ${log-lib} ) \ No newline at end of file +endif() diff --git a/AS3/app/build.gradle b/AS3/app/build.gradle index e4e655a..6aaf8dc 100644 --- a/AS3/app/build.gradle +++ b/AS3/app/build.gradle @@ -1,7 +1,6 @@ apply plugin: 'com.android.application' -//apply plugin: 'kotlin-android' -//apply plugin: 'kotlin-android-extensions' -//apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' // Manifest version information def versionMajor = 3 @@ -39,16 +38,42 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) -// implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation 'com.android.support:appcompat-v7:27.0.1' implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' testImplementation 'junit:junit:4.12' } +// TODO: Expose this to the test project +def osxDir = projectDir.absolutePath + '/.externalNativeBuild/cmake/debug/osx/' + +task createBuildDir() { + def folder = new File(osxDir) + if (!folder.exists()) { + folder.mkdirs() + } +} + +task runCMake(type: Exec) { + dependsOn createBuildDir + workingDir osxDir // Jump to future build directory + commandLine '/usr/local/bin/cmake' // Path from HomeBrew installation + args '../../../../' // Relative path for out-of-source builds +} + +task runMake(type: Exec) { + dependsOn runCMake + workingDir osxDir + commandLine 'make' +} + project.afterEvaluate { // Not sure how much of a hack this is - but it allows CMake/SWIG to run before Android Studio // complains about missing generated files // TODO: Probably need a release hook too? javaPreCompileDebug.dependsOn externalNativeBuildDebug + if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) { + javaPreCompileDebugAndroidTest.dependsOn runMake + } } diff --git a/AS3/app/src/test/java/com/sureshjoshi/android/ndkexample/ExampleUnitTest.kt b/AS3/app/src/test/java/com/sureshjoshi/android/ndkexample/ExampleUnitTest.kt deleted file mode 100644 index da0d50c..0000000 --- a/AS3/app/src/test/java/com/sureshjoshi/android/ndkexample/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.sureshjoshi.android.ndkexample - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/AS3/app/src/test/java/com/sureshjoshi/android/ndkexample/NativeUnitTest.kt b/AS3/app/src/test/java/com/sureshjoshi/android/ndkexample/NativeUnitTest.kt new file mode 100644 index 0000000..cbccb68 --- /dev/null +++ b/AS3/app/src/test/java/com/sureshjoshi/android/ndkexample/NativeUnitTest.kt @@ -0,0 +1,23 @@ +package com.sureshjoshi.android.ndkexample + +import org.junit.Assert +import org.junit.Test +import java.io.File + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class NativeUnitTest { + @Test + fun addition_isCorrect() { + // TODO: Read this directory from Gradle + val wrapperLib = File("app/.externalNativeBuild/cmake/debug/osx/libSeePlusPlus_Wrapper.jnilib") + System.out.println(wrapperLib.absolutePath) + System.load(wrapperLib.absolutePath) + val mCpp = SeePlusPlus() + val result = mCpp.Multiply(5, 1) + Assert.assertEquals(5, result) + } +} diff --git a/AS3/build.gradle b/AS3/build.gradle index 97c0cf8..d7d41fa 100644 --- a/AS3/build.gradle +++ b/AS3/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.1.51' + ext.kotlin_version = '1.1.60' repositories { google() jcenter()