diff --git a/cmake/android/android_gradle_projects.cmake b/cmake/android/android_gradle_projects.cmake index 2b79806fa8..227d559c27 100644 --- a/cmake/android/android_gradle_projects.cmake +++ b/cmake/android/android_gradle_projects.cmake @@ -2,7 +2,7 @@ set(ANDROID_GRADLE_PLUGIN_VERSION "7.3.1" CACHE STRING "Android Gradle Plugin version") message(STATUS "Android Gradle Plugin version: ${ANDROID_GRADLE_PLUGIN_VERSION}") -set(KOTLIN_PLUGIN_VERSION "1.5.20" CACHE STRING "Kotlin Plugin version") +set(KOTLIN_PLUGIN_VERSION "1.8.20" CACHE STRING "Kotlin Plugin version") message(STATUS "Kotlin Plugin version: ${KOTLIN_PLUGIN_VERSION}") if(BUILD_KOTLIN_EXTENSIONS) diff --git a/modules/java/test/android_test/CMakeLists.txt b/modules/java/test/android_test/CMakeLists.txt index aac98eaf23..c7f254e850 100644 --- a/modules/java/test/android_test/CMakeLists.txt +++ b/modules/java/test/android_test/CMakeLists.txt @@ -10,12 +10,13 @@ set(ANDROID_TESTS_SRC_DIRS set(ANDROID_TESTS_RES_DIR "'${OpenCV_SOURCE_DIR}/modules/java/test/common_test/res'" CACHE INTERNAL "") -list(APPEND TEST_PROJECT_FILES "build.gradle" "CMakeLists.txt" "gradle.properties" "settings.gradle") +list(APPEND TEST_PROJECT_FILES "CMakeLists.txt" "gradle.properties" "settings.gradle") foreach(TEST_PROJECT_FILE ${TEST_PROJECT_FILES}) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PROJECT_FILE}" DESTINATION "${OPENCV_ANDROID_TEST_DIR}") endforeach() file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests_module/AndroidManifest.xml" DESTINATION "${OPENCV_ANDROID_TEST_DIR}/tests_module") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tests_module/build.gradle.in" "${OPENCV_ANDROID_TEST_DIR}/tests_module/build.gradle" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${OPENCV_ANDROID_TEST_DIR}/build.gradle" @ONLY) file(COPY "${OpenCV_SOURCE_DIR}/platforms/android/gradle-wrapper/gradlew" DESTINATION "${OPENCV_ANDROID_TEST_DIR}") file(COPY "${OpenCV_SOURCE_DIR}/platforms/android/gradle-wrapper/gradlew.bat" DESTINATION "${OPENCV_ANDROID_TEST_DIR}") diff --git a/modules/java/test/android_test/build.gradle b/modules/java/test/android_test/build.gradle.in similarity index 73% rename from modules/java/test/android_test/build.gradle rename to modules/java/test/android_test/build.gradle.in index 8334980b76..812268f0ab 100644 --- a/modules/java/test/android_test/build.gradle +++ b/modules/java/test/android_test/build.gradle.in @@ -7,8 +7,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20' + classpath 'com.android.tools.build:gradle:@ANDROID_GRADLE_PLUGIN_VERSION@' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:@KOTLIN_PLUGIN_VERSION@' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/modules/java/test/android_test/src/org/opencv/test/android/KotlinTest.kt b/modules/java/test/android_test/src/org/opencv/test/android/KotlinTest.kt new file mode 100644 index 0000000000..8803cf9ee7 --- /dev/null +++ b/modules/java/test/android_test/src/org/opencv/test/android/KotlinTest.kt @@ -0,0 +1,25 @@ +package org.opencv.test.android + +import org.opencv.core.CvType +import org.opencv.core.Mat +import org.opencv.core.times +import org.opencv.test.OpenCVTestCase +import kotlin.math.abs + +class KotlinTest : OpenCVTestCase() { + fun testMatrixMultiplication() { + val m1 = Mat.ones(2, 3, CvType.CV_32F) + val m2 = Mat.ones(3, 2, CvType.CV_32F) + + val m3 = m1.matMul(m2) + val m4 = m1 * m2 + + val value1 = floatArrayOf(3f) + m3.get(0, 1, value1) + + val value2 = floatArrayOf(5f) + m4[0, 1, value2] + + assertGE(0.001, abs(value1[0] - value2[0]).toDouble()) + } +} diff --git a/modules/java/test/android_test/tests_module/build.gradle.in b/modules/java/test/android_test/tests_module/build.gradle.in index 1b8cc0260c..049e6546bd 100644 --- a/modules/java/test/android_test/tests_module/build.gradle.in +++ b/modules/java/test/android_test/tests_module/build.gradle.in @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' android { namespace 'org.opencv.tests' diff --git a/platforms/android/ndk-25.config.py b/platforms/android/ndk-25.config.py index b6b12126eb..5ca8525d5c 100644 --- a/platforms/android/ndk-25.config.py +++ b/platforms/android/ndk-25.config.py @@ -9,7 +9,7 @@ cmake_common_vars = { # Docs: https://developer.android.com/studio/releases/gradle-plugin 'ANDROID_GRADLE_PLUGIN_VERSION': '7.3.1', 'GRADLE_VERSION': '7.5.1', - 'KOTLIN_PLUGIN_VERSION': '1.5.20', + 'KOTLIN_PLUGIN_VERSION': '1.8.20', } ABIs = [ ABI("2", "armeabi-v7a", None, ndk_api_level=ANDROID_NATIVE_API_LEVEL, cmake_vars=cmake_common_vars),