diff --git a/modules/java/android_sdk/CMakeLists.txt b/modules/java/android_sdk/CMakeLists.txt index b5fbc3d93d..a9e6ff52af 100644 --- a/modules/java/android_sdk/CMakeLists.txt +++ b/modules/java/android_sdk/CMakeLists.txt @@ -15,6 +15,59 @@ file(MAKE_DIRECTORY "${java_src_dir}") ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/java" "${java_src_dir}") +set(SOURSE_SETS_JNI_LIBS_SRC_DIRS "'native/libs'") +set(SOURSE_SETS_JAVA_SRC_DIRS "'java/src'") +set(SOURSE_SETS_RES_SRC_DIRS "'java/res'") +set(SOURSE_SETS_MANIFEST_SRC_FILE "'java/AndroidManifest.xml'") +set(BUILD_GRADLE_COMPILE_OPTIONS " + compileOptions { + sourceCompatibility JavaVersion.VERSION_${ANDROID_GRADLE_JAVA_VERSION_INIT} + targetCompatibility JavaVersion.VERSION_${ANDROID_GRADLE_JAVA_VERSION_INIT} + } +") +set(MAVEN_PUBLISH_PLUGIN_DECLARATION "apply plugin: 'maven-publish'") +set(BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG " + buildFeatures { + prefabPublishing true + buildConfig true + } + + prefab { + opencv_jni_shared { + headers 'native/jni/include' + } + } + + publishing { + singleVariant('release') { + withSourcesJar() + withJavadocJar() + } + } +") + +set(BUILD_GRADLE_PUBLISHING_CONFIG " +publishing { + publications { + release(MavenPublication) { + groupId = 'org.opencv' + artifactId = 'opencv' + version = '${OPENCV_VERSION_PLAIN}' + + afterEvaluate { + from components.release + } + } + } + repositories { + maven { + name = 'myrepo' + url = \"\${project.buildDir}/repo\" + } + } +} +") + if(ANDROID_EXECUTABLE) ocv_assert(ANDROID_TOOLS_Pkg_Revision GREATER 13) @@ -108,6 +161,7 @@ if(ANDROID_NATIVE_API_LEVEL GREATER 21) else() ocv_update(ANDROID_TARGET_SDK_VERSION "21") endif() + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/build.gradle" DESTINATION ${JAVA_INSTALL_ROOT}/.. COMPONENT java) @@ -117,12 +171,23 @@ else() # gradle build # Android Gradle-based project # +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" @ONLY) + #TODO: INSTALL ONLY ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android/java" "${java_src_dir}") ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-21/java" "${java_src_dir}") ocv_copyfiles_append_dir(JAVA_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/android-24/java" "${java_src_dir}") # copy boilerplate +set(SOURSE_SETS_JNI_LIBS_SRC_DIRS "'../../jni'") +set(SOURSE_SETS_JAVA_SRC_DIRS "'src'") +set(SOURSE_SETS_RES_SRC_DIRS "'${OpenCV_SOURCE_DIR}/modules/java/android_sdk/android_gradle_lib/res'") +set(SOURSE_SETS_MANIFEST_SRC_FILE "'AndroidManifest.xml'") +set(BUILD_GRADLE_COMPILE_OPTIONS "") +set(MAVEN_PUBLISH_PLUGIN_DECLARATION "") +set(BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG "") +set(BUILD_GRADLE_PUBLISHING_CONFIG "") + set(__base_dir "${CMAKE_CURRENT_SOURCE_DIR}/android_gradle_lib/") file(GLOB_RECURSE seed_project_files_rel RELATIVE "${__base_dir}/" "${__base_dir}/*") list(REMOVE_ITEM seed_project_files_rel "${ANDROID_MANIFEST_FILE}") @@ -134,6 +199,7 @@ foreach(file ${seed_project_files_rel}) install(FILES "${OPENCV_JAVA_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java) endif() endforeach() +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${OPENCV_JAVA_DIR}/build.gradle" @ONLY) # copy libcxx_helper set(__base_dir "${CMAKE_CURRENT_SOURCE_DIR}/") @@ -165,7 +231,6 @@ file(REMOVE "${OPENCV_DEPHELPER}/${the_module}_android") # force rebuild after add_custom_target(${the_module}_android ALL DEPENDS "${OPENCV_DEPHELPER}/${the_module}_android" SOURCES "${__base_dir}/${ANDROID_MANIFEST_FILE}") -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.gradle.in" "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" @ONLY) install(FILES "${ANDROID_TMP_INSTALL_BASE_DIR}/opencv/build.gradle" DESTINATION ${JAVA_INSTALL_ROOT}/.. COMPONENT java) install(DIRECTORY "${java_src_dir}" DESTINATION "${JAVA_INSTALL_ROOT}" COMPONENT java) diff --git a/modules/java/android_sdk/android_gradle_lib/build.gradle b/modules/java/android_sdk/android_gradle_lib/build.gradle deleted file mode 100644 index 4394bd9a4e..0000000000 --- a/modules/java/android_sdk/android_gradle_lib/build.gradle +++ /dev/null @@ -1,58 +0,0 @@ -apply plugin: 'com.android.library' -@KOTLIN_PLUGIN_DECLARATION@ - -def openCVersionName = "@OPENCV_VERSION@" -def openCVersionCode = ((@OPENCV_VERSION_MAJOR@ * 100 + @OPENCV_VERSION_MINOR@) * 100 + @OPENCV_VERSION_PATCH@) * 10 + 0 - -android { - @OPENCV_ANDROID_NAMESPACE_DECLARATION@ - compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@ - - defaultConfig { - minSdkVersion @ANDROID_MIN_SDK_VERSION@ - targetSdkVersion @ANDROID_TARGET_SDK_VERSION@ - - versionCode openCVersionCode - versionName openCVersionName - - externalNativeBuild { - cmake { - arguments "-DANDROID_STL=@ANDROID_STL@" - targets "opencv_jni_shared" - } - } - } - - buildTypes { - debug { - packagingOptions { - doNotStrip '**/*.so' // controlled by OpenCV CMake scripts - } - } - release { - packagingOptions { - doNotStrip '**/*.so' // controlled by OpenCV CMake scripts - } - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } - - sourceSets { - main { - jniLibs.srcDirs = ['../../jni'] - java.srcDirs = ['src'] // TODO Use original files instead of copied into build directory - res.srcDirs = ['@OpenCV_SOURCE_DIR@/modules/java/android_sdk/android_gradle_lib/res'] - manifest.srcFile 'AndroidManifest.xml' - } - } - - externalNativeBuild { - cmake { - path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt') - } - } -} - -dependencies { -} diff --git a/modules/java/android_sdk/build.gradle.in b/modules/java/android_sdk/build.gradle.in index 85e5c049fb..1dcae31444 100644 --- a/modules/java/android_sdk/build.gradle.in +++ b/modules/java/android_sdk/build.gradle.in @@ -89,7 +89,7 @@ // apply plugin: 'com.android.library' -apply plugin: 'maven-publish' +@MAVEN_PUBLISH_PLUGIN_DECLARATION@ try { @KOTLIN_PLUGIN_DECLARATION@ println "Configure OpenCV with Kotlin" @@ -120,12 +120,7 @@ android { } } } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION_INIT@ - targetCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION_INIT@ - } - + @BUILD_GRADLE_COMPILE_OPTIONS@ buildTypes { debug { packagingOptions { @@ -141,29 +136,12 @@ android { } } - buildFeatures { - prefabPublishing true - buildConfig true - } - prefab { - opencv_jni_shared { - headers "native/jni/include" - } - } - sourceSets { main { - jniLibs.srcDirs = ['native/libs'] - java.srcDirs = ['java/src'] - res.srcDirs = ['java/res'] - manifest.srcFile 'java/AndroidManifest.xml' - } - } - - publishing { - singleVariant('release') { - withSourcesJar() - withJavadocJar() + jniLibs.srcDirs = [@SOURSE_SETS_JNI_LIBS_SRC_DIRS@] + java.srcDirs = [@SOURSE_SETS_JAVA_SRC_DIRS@] + res.srcDirs = [@SOURSE_SETS_RES_SRC_DIRS@] + manifest.srcFile @SOURSE_SETS_MANIFEST_SRC_FILE@ } } @@ -172,27 +150,8 @@ android { path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt') } } + @BUILD_GRADLE_ANDROID_PUBLISHING_CONFIG@ } - -publishing { - publications { - release(MavenPublication) { - groupId = 'org.opencv' - artifactId = 'opencv' - version = '@OPENCV_VERSION_PLAIN@' - - afterEvaluate { - from components.release - } - } - } - repositories { - maven { - name = 'myrepo' - url = "${project.buildDir}/repo" - } - } -} - +@BUILD_GRADLE_PUBLISHING_CONFIG@ dependencies { }