Added Kotlin test, changed Kotlin version for OpenCV

pull/24946/head
Alexander Lyulkov 10 months ago committed by Alexander Smorkalov
parent 4b35b2f968
commit 02b3518a3b
  1. 2
      cmake/android/android_gradle_projects.cmake
  2. 3
      modules/java/test/android_test/CMakeLists.txt
  3. 4
      modules/java/test/android_test/build.gradle.in
  4. 25
      modules/java/test/android_test/src/org/opencv/test/android/KotlinTest.kt
  5. 1
      modules/java/test/android_test/tests_module/build.gradle.in
  6. 2
      platforms/android/ndk-25.config.py

@ -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)

@ -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}")

@ -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

@ -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())
}
}

@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
namespace 'org.opencv.tests'

@ -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),

Loading…
Cancel
Save