opencv/samples/android/build.gradle.in
Alexander Smorkalov c803aa2ddd
Merge pull request #26057 from asmorkalov:as/android_16k_pages
Android builds update #26057

Fixes https://github.com/opencv/opencv/issues/26027
Should also address https://github.com/opencv/opencv/issues/26542
 
Changes:
- Switched to Android build tools 34, NDK 26d, target API level 34 (required by Google Play).
- Use flexible page size on Android by default to support Android 15+.
- Dummy stub for R and BuildConfig classes for javadoc.
- Java 17 everywhere.
- Strict ndkVersion and ABI list in release package.

Related:
- Docker: https://github.com/opencv-infrastructure/opencv-gha-dockerfile/pull/41
- Pipeline: https://github.com/opencv/ci-gha-workflow/pull/183

Related IPP issue with NDK 27+: https://github.com/opencv/opencv/issues/26072

Google documentation for 16kb pages support : https://developer.android.com/guide/practices/page-sizes?hl=en

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2024-12-31 11:53:04 +03:00

110 lines
3.5 KiB
Groovy

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
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
}
}
allprojects {
repositories {
google()
jcenter()
if (gradle.opencv_source == "maven_local") {
maven {
url gradle.opencv_maven_path
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
//allprojects {
// gradle.projectsEvaluated {
// tasks.withType(JavaCompile) {
// options.compilerArgs << "-Xlint:unchecked"
// options.compilerArgs << "-Xlint:deprecation"
// }
// }
//}
def opencv_strict_build_configuration = @ANDROID_STRICT_BUILD_CONFIGURATION@;
gradle.afterProject { project ->
if (project.pluginManager.hasPlugin('com.android.application')
|| project.pluginManager.hasPlugin('com.android.library')
|| project.pluginManager.hasPlugin('com.android.test')
|| project.pluginManager.hasPlugin('com.android.feature') ) {
if (true) {
gradle.println("Override build ABIs for the project ${project.name}")
project.android {
splits {
abi {
enable true
universalApk false
@ANDROID_ABI_FILTER@
}
}
}
}
if (true) {
gradle.println("Override lintOptions for the project ${project.name}")
project.android {
lintOptions {
// checkReleaseBuilds false
abortOnError false
}
}
}
// (you still need to re-build OpenCV with debug information to debug it)
if (true) {
gradle.println("Override doNotStrip-debug for the project ${project.name}")
project.android {
buildTypes {
debug {
packagingOptions {
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
}
}
}
}
}
if (false || project.hasProperty("doNotStrip")) {
gradle.println("Override doNotStrip-release for the project ${project.name}")
project.android {
buildTypes {
release {
packagingOptions {
doNotStrip '**/*.so' // controlled by OpenCV CMake scripts
}
}
}
}
}
// Android Gradle Plugin (AGP) 3.5+ is required
// https://github.com/android/ndk-samples/wiki/Configure-NDK-Path
def isNdkVersionSupported = project.android.metaClass.getProperties().find { it.name == 'ndkVersion' } != null
if (opencv_strict_build_configuration && isNdkVersionSupported) {
gradle.println("Override ndkVersion for the project ${project.name}")
project.android {
ndkVersion '@ANDROID_NDK_REVISION@'
}
}
}
}