diff --git a/android/openthread_commissioner/service/build.gradle b/android/openthread_commissioner/service/build.gradle index 6e0894c7..db3db7b2 100644 --- a/android/openthread_commissioner/service/build.gradle +++ b/android/openthread_commissioner/service/build.gradle @@ -39,6 +39,32 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" + + externalNativeBuild { + cmake { + arguments "-DOT_COMM_ANDROID=ON", + "-DOT_COMM_JAVA_BINDING=ON", + "-DBUILD_SHARED_LIBS=OFF", + "-DCMAKE_CXX_STANDARD=11", + "-DCMAKE_CXX_STANDARD_REQUIRED=ON", + "-DCMAKE_BUILD_TYPE=Release", + "-DOT_COMM_APP=OFF", + "-DOT_COMM_TEST=OFF", + "-DOT_COMM_CCM=OFF", + "-DOT_COMM_JAR_DIR=libs" + + targets "commissioner-java", "commissioner-java-lib" + } + } + } + + externalNativeBuild { + + // Encapsulates your CMake build configurations. + cmake { + // Provides a relative path to your CMake build script. + path "../../../CMakeLists.txt" + } } buildTypes { @@ -52,6 +78,15 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } namespace 'io.openthread.commissioner.service' + sourceSets.main.java.srcDirs += 'src/genlibs/java' +} + +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? + compileDebugJavaWithJavac.dependsOn externalNativeBuildDebug + javaPreCompileRelease.dependsOn externalNativeBuildRelease } // This is for the local tests (src/test) to find the native libraries. diff --git a/src/java/CMakeLists.txt b/src/java/CMakeLists.txt index 9c54ec77..6281222c 100644 --- a/src/java/CMakeLists.txt +++ b/src/java/CMakeLists.txt @@ -27,7 +27,6 @@ # set(JAVA_PACKAGE_NAME io.openthread.commissioner) -set(JAVA_OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/io/openthread/commissioner) find_package(SWIG 4.0 REQUIRED) find_package(Java REQUIRED) @@ -74,6 +73,14 @@ install(TARGETS commissioner-java LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +get_property(GENERATED_JAVA_SRCS TARGET commissioner-java PROPERTY SWIG_SUPPORT_FILES) + +add_jar(commissioner-java-lib + ${GENERATED_JAVA_SRCS} +) + +add_dependencies(commissioner-java-lib commissioner-java) + ## It is useful that the output directory can be configured when ## OT commissioner is integrated with an existing Android application. if (OT_COMM_JAVA_BINDING_OUTDIR) @@ -82,5 +89,5 @@ if (OT_COMM_JAVA_BINDING_OUTDIR) COMMAND cp io/openthread/commissioner/*.java ${OT_COMM_JAVA_BINDING_OUTDIR}/io/openthread/commissioner WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "packing generated Java source files..." - ) + ) endif()