From a31e35cc719870b4656582368a3c068fe3b71b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E5=9B=A0=E6=96=AF=E5=94=90?= <1745525+einsitang@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:44:03 +0000 Subject: [PATCH 1/3] android auto ignore unuse abi --- packages/opencv_core/android/build.gradle | 65 ++++++++++++++++------- packages/opencv_dart/android/build.gradle | 30 +++++++++++ 2 files changed, 77 insertions(+), 18 deletions(-) diff --git a/packages/opencv_core/android/build.gradle b/packages/opencv_core/android/build.gradle index d984b981..8d373aec 100644 --- a/packages/opencv_core/android/build.gradle +++ b/packages/opencv_core/android/build.gradle @@ -1,7 +1,7 @@ // The Android Gradle Plugin builds the native code with the Android NDK. -group = "dev.rainyl.opencv_core" -version = "1.0" +group = 'dev.rainyl.opencv_core' +version = '1.0' buildscript { repositories { @@ -11,7 +11,7 @@ buildscript { dependencies { // The Android Gradle Plugin knows how to build native code with the NDK. - classpath("com.android.tools.build:gradle:8.1.0") + classpath('com.android.tools.build:gradle:8.1.0') } } @@ -22,13 +22,13 @@ rootProject.allprojects { } } -apply plugin: "com.android.library" +apply plugin: 'com.android.library' def SOURCE_DIR = project.buildscript.sourceFile.parentFile android { - if (project.android.hasProperty("namespace")) { - namespace = "dev.rainyl.opencv_core" + if (project.android.hasProperty('namespace')) { + namespace = 'dev.rainyl.opencv_core' } // Bumping the plugin compileSdk version requires all clients of this plugin @@ -44,15 +44,15 @@ android { // Invoke the shared CMake build with the Android Gradle Plugin. externalNativeBuild { cmake { - path = "../src/CMakeLists.txt" - - // The default CMake version for the Android Gradle Plugin is 3.10.2. - // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake - // - // The Flutter tooling requires that developers have CMake 3.10 or later - // installed. You should not increase this version, as doing so will cause - // the plugin to fail to compile for some customers of the plugin. - // version "3.10.2" + path = '../src/CMakeLists.txt' + + // The default CMake version for the Android Gradle Plugin is 3.10.2. + // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake + // + // The Flutter tooling requires that developers have CMake 3.10 or later + // installed. You should not increase this version, as doing so will cause + // the plugin to fail to compile for some customers of the plugin. + // version "3.10.2" } } @@ -67,8 +67,8 @@ android { // Invoke the shared CMake build with the Android Gradle Plugin. externalNativeBuild { cmake { - arguments "-DANDROID_ARM_NEON=TRUE", - "-DANDROID_STL=c++_static", + arguments '-DANDROID_ARM_NEON=TRUE', + '-DANDROID_STL=c++_static', "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" } } @@ -77,7 +77,36 @@ android { release { externalNativeBuild { cmake { - arguments "-DCMAKE_BUILD_TYPE=Release" + arguments '-DCMAKE_BUILD_TYPE=Release' + } + } + + def targetPlatforms = project.getProperty('target-platform').split(',') as List + if (!targetPlatforms.isEmpty()) { + // ignore not use abi + def excludeList = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] + + targetPlatforms.each { platform -> + if (platform.equals('android-arm64')) { + excludeList.remove('arm64-v8a') + } + if (platform.equals('android-arm')) { + excludeList.remove('armeabi-v7a') + } + if (platform.equals('android-x86')) { + excludeList.remove('x86') + } + if (platform.equals('android-x64')) { + excludeList.remove('x86_64') + } + } + + println "[OPENCV_CORE] only support platform : $targetPlatforms" + println "[OPENCV_CORE] exclude abi : $excludeList" + packagingOptions { + excludeList.each { + exclude "lib/$it/*" + } } } } diff --git a/packages/opencv_dart/android/build.gradle b/packages/opencv_dart/android/build.gradle index 997f5fb5..567b69c9 100644 --- a/packages/opencv_dart/android/build.gradle +++ b/packages/opencv_dart/android/build.gradle @@ -78,6 +78,36 @@ android { } } } + + def targetPlatforms = project.getProperty('target-platform').split(',') as List + if (!targetPlatforms.isEmpty()) { + // ignore not use abi + def excludeList = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] + + targetPlatforms.each { platform -> + if (platform.equals('android-arm64')) { + excludeList.remove('arm64-v8a') + } + if (platform.equals('android-arm')) { + excludeList.remove('armeabi-v7a') + } + if (platform.equals('android-x86')) { + excludeList.remove('x86') + } + if (platform.equals('android-x64')) { + excludeList.remove('x86_64') + } + } + + println "[OPENCV_CORE] only support platform : $targetPlatforms" + println "[OPENCV_CORE] exclude abi : $excludeList" + packagingOptions { + excludeList.each { + exclude "lib/$it/*" + } + } + } + } } } } From 4da37a55093e02209d867da8c9f10bbd0cd90a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E5=9B=A0=E6=96=AF=E5=94=90?= <1745525+einsitang@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:53:43 +0000 Subject: [PATCH 2/3] fix opencv_dart format --- packages/opencv_dart/android/build.gradle | 49 +++++++++++------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/packages/opencv_dart/android/build.gradle b/packages/opencv_dart/android/build.gradle index 567b69c9..6940711e 100644 --- a/packages/opencv_dart/android/build.gradle +++ b/packages/opencv_dart/android/build.gradle @@ -77,37 +77,36 @@ android { arguments "-DCMAKE_BUILD_TYPE=Release" } } - } - - def targetPlatforms = project.getProperty('target-platform').split(',') as List - if (!targetPlatforms.isEmpty()) { - // ignore not use abi - def excludeList = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] - targetPlatforms.each { platform -> - if (platform.equals('android-arm64')) { - excludeList.remove('arm64-v8a') - } - if (platform.equals('android-arm')) { - excludeList.remove('armeabi-v7a') - } - if (platform.equals('android-x86')) { - excludeList.remove('x86') + def targetPlatforms = project.getProperty('target-platform').split(',') as List + if (!targetPlatforms.isEmpty()) { + // ignore not use abi + def excludeList = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] + + targetPlatforms.each { platform -> + if (platform.equals('android-arm64')) { + excludeList.remove('arm64-v8a') + } + if (platform.equals('android-arm')) { + excludeList.remove('armeabi-v7a') + } + if (platform.equals('android-x86')) { + excludeList.remove('x86') + } + if (platform.equals('android-x64')) { + excludeList.remove('x86_64') + } } - if (platform.equals('android-x64')) { - excludeList.remove('x86_64') - } - } - println "[OPENCV_CORE] only support platform : $targetPlatforms" - println "[OPENCV_CORE] exclude abi : $excludeList" - packagingOptions { - excludeList.each { - exclude "lib/$it/*" + println "[OPENCV_CORE] only support platform : $targetPlatforms" + println "[OPENCV_CORE] exclude abi : $excludeList" + packagingOptions { + excludeList.each { + exclude "lib/$it/*" + } } } } - } } } } From 72a6f95b2aeb912d9826729651c3efe353d5cce8 Mon Sep 17 00:00:00 2001 From: rainyl Date: Mon, 24 Mar 2025 21:02:28 +0800 Subject: [PATCH 3/3] format android build script --- packages/opencv_core/.gitignore | 1 + packages/opencv_core/android/build.gradle | 155 +++++++++++---------- packages/opencv_dart/.gitignore | 1 + packages/opencv_dart/android/build.gradle | 157 +++++++++++----------- 4 files changed, 153 insertions(+), 161 deletions(-) diff --git a/packages/opencv_core/.gitignore b/packages/opencv_core/.gitignore index ac5aa989..295ab644 100644 --- a/packages/opencv_core/.gitignore +++ b/packages/opencv_core/.gitignore @@ -9,6 +9,7 @@ .history .svn/ migrate_working_dir/ +.cxx/ # IntelliJ related *.iml diff --git a/packages/opencv_core/android/build.gradle b/packages/opencv_core/android/build.gradle index 8d373aec..493e062d 100644 --- a/packages/opencv_core/android/build.gradle +++ b/packages/opencv_core/android/build.gradle @@ -4,22 +4,22 @@ group = 'dev.rainyl.opencv_core' version = '1.0' buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - // The Android Gradle Plugin knows how to build native code with the NDK. - classpath('com.android.tools.build:gradle:8.1.0') - } + repositories { + google() + mavenCentral() + } + + dependencies { + // The Android Gradle Plugin knows how to build native code with the NDK. + classpath('com.android.tools.build:gradle:8.1.0') + } } rootProject.allprojects { - repositories { - google() - mavenCentral() - } + repositories { + google() + mavenCentral() + } } apply plugin: 'com.android.library' @@ -27,89 +27,84 @@ apply plugin: 'com.android.library' def SOURCE_DIR = project.buildscript.sourceFile.parentFile android { - if (project.android.hasProperty('namespace')) { - namespace = 'dev.rainyl.opencv_core' + if (project.android.hasProperty('namespace')) { + namespace = 'dev.rainyl.opencv_core' + } + + // Bumping the plugin compileSdk version requires all clients of this plugin + // to bump the version in their app. + compileSdk = 33 + + // Use the NDK version + // declared in /android/app/build.gradle file of the Flutter project. + // Replace it with a version number if this plugin requires a specific NDK version. + // (e.g. ndkVersion "23.1.7779620") + // ndkVersion = android.ndkVersion + + // Invoke the shared CMake build with the Android Gradle Plugin. + externalNativeBuild { + cmake { + path = '../src/CMakeLists.txt' + + // The default CMake version for the Android Gradle Plugin is 3.10.2. + // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake + // + // The Flutter tooling requires that developers have CMake 3.10 or later + // installed. You should not increase this version, as doing so will cause + // the plugin to fail to compile for some customers of the plugin. + // version "3.10.2" } + } - // Bumping the plugin compileSdk version requires all clients of this plugin - // to bump the version in their app. - compileSdk = 33 + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } - // Use the NDK version - // declared in /android/app/build.gradle file of the Flutter project. - // Replace it with a version number if this plugin requires a specific NDK version. - // (e.g. ndkVersion "23.1.7779620") - // ndkVersion = android.ndkVersion + defaultConfig { + minSdkVersion 24 // Invoke the shared CMake build with the Android Gradle Plugin. externalNativeBuild { - cmake { - path = '../src/CMakeLists.txt' - - // The default CMake version for the Android Gradle Plugin is 3.10.2. - // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake - // - // The Flutter tooling requires that developers have CMake 3.10 or later - // installed. You should not increase this version, as doing so will cause - // the plugin to fail to compile for some customers of the plugin. - // version "3.10.2" - } - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + cmake { + arguments '-DANDROID_ARM_NEON=TRUE', + '-DANDROID_STL=c++_static', + "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" + } } - defaultConfig { - minSdkVersion 24 - - // Invoke the shared CMake build with the Android Gradle Plugin. - externalNativeBuild { + buildTypes { + release { + externalNativeBuild { cmake { - arguments '-DANDROID_ARM_NEON=TRUE', - '-DANDROID_STL=c++_static', - "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" + arguments '-DCMAKE_BUILD_TYPE=Release' } - } + } - buildTypes { - release { - externalNativeBuild { - cmake { - arguments '-DCMAKE_BUILD_TYPE=Release' - } - } + def targetPlatforms = project.getProperty('target-platform').split(',') as List + if (!targetPlatforms.isEmpty()) { + def platformAbiMap = [ + 'android-arm64': 'arm64-v8a', + 'android-arm' : 'armeabi-v7a', + 'android-x86' : 'x86', + 'android-x64' : 'x86_64' + ] - def targetPlatforms = project.getProperty('target-platform').split(',') as List - if (!targetPlatforms.isEmpty()) { - // ignore not use abi - def excludeList = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] - - targetPlatforms.each { platform -> - if (platform.equals('android-arm64')) { - excludeList.remove('arm64-v8a') - } - if (platform.equals('android-arm')) { - excludeList.remove('armeabi-v7a') - } - if (platform.equals('android-x86')) { - excludeList.remove('x86') - } - if (platform.equals('android-x64')) { - excludeList.remove('x86_64') - } - } + def excludeList = platformAbiMap.values() as List + + targetPlatforms.each { platform -> + excludeList.remove(platformAbiMap[platform]) + } - println "[OPENCV_CORE] only support platform : $targetPlatforms" - println "[OPENCV_CORE] exclude abi : $excludeList" - packagingOptions { - excludeList.each { - exclude "lib/$it/*" - } + logger.info "[OPENCV_CORE] building for platforms: $targetPlatforms" + logger.info "[OPENCV_CORE] excluded abis: $excludeList" + packagingOptions { + excludeList.each { abi -> + exclude "lib/$abi/*" } } } } } + } } diff --git a/packages/opencv_dart/.gitignore b/packages/opencv_dart/.gitignore index ac5aa989..295ab644 100644 --- a/packages/opencv_dart/.gitignore +++ b/packages/opencv_dart/.gitignore @@ -9,6 +9,7 @@ .history .svn/ migrate_working_dir/ +.cxx/ # IntelliJ related *.iml diff --git a/packages/opencv_dart/android/build.gradle b/packages/opencv_dart/android/build.gradle index 6940711e..41930cdf 100644 --- a/packages/opencv_dart/android/build.gradle +++ b/packages/opencv_dart/android/build.gradle @@ -2,22 +2,22 @@ group 'dev.rainyl.opencv_dart' version '1.0' buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - // The Android Gradle Plugin knows how to build native code with the NDK. - classpath("com.android.tools.build:gradle:8.1.0") - } + repositories { + google() + mavenCentral() + } + + dependencies { + // The Android Gradle Plugin knows how to build native code with the NDK. + classpath("com.android.tools.build:gradle:8.1.0") + } } rootProject.allprojects { - repositories { - google() - mavenCentral() - } + repositories { + google() + mavenCentral() + } } apply plugin: 'com.android.library' @@ -25,88 +25,83 @@ apply plugin: 'com.android.library' def SOURCE_DIR = project.buildscript.sourceFile.parentFile android { - if (project.android.hasProperty("namespace")) { - namespace 'dev.rainyl.opencv_dart' + if (project.android.hasProperty("namespace")) { + namespace 'dev.rainyl.opencv_dart' + } + + // Bumping the plugin compileSdk version requires all clients of this plugin + // to bump the version in their app. + compileSdk 33 + + // Use the NDK version declared in /android/app/build.gradle file of the Flutter project. + // Replace it with a version number if this plugin requires a specific NDK version. + // (e.g. ndkVersion "23.1.7779620") + // ndkVersion = android.ndkVersion + + // Invoke the shared CMake build with the Android Gradle Plugin. + externalNativeBuild { + cmake { + path "../src/CMakeLists.txt" + + // The default CMake version for the Android Gradle Plugin is 3.10.2. + // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake + // + // The Flutter tooling requires that developers have CMake 3.10 or later + // installed. You should not increase this version, as doing so will cause + // the plugin to fail to compile for some customers of the plugin. + // version "3.10.2" } + } - // Bumping the plugin compileSdk version requires all clients of this plugin - // to bump the version in their app. - compileSdk 33 + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } - // Use the NDK version declared in /android/app/build.gradle file of the Flutter project. - // Replace it with a version number if this plugin requires a specific NDK version. - // (e.g. ndkVersion "23.1.7779620") - // ndkVersion = android.ndkVersion + defaultConfig { + minSdkVersion 24 // Invoke the shared CMake build with the Android Gradle Plugin. externalNativeBuild { - cmake { - path "../src/CMakeLists.txt" - - // The default CMake version for the Android Gradle Plugin is 3.10.2. - // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake - // - // The Flutter tooling requires that developers have CMake 3.10 or later - // installed. You should not increase this version, as doing so will cause - // the plugin to fail to compile for some customers of the plugin. - // version "3.10.2" - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + cmake { + arguments "-DANDROID_ARM_NEON=TRUE", + "-DANDROID_STL=c++_static", + "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" + } } - defaultConfig { - minSdkVersion 24 - - // Invoke the shared CMake build with the Android Gradle Plugin. + buildTypes { + release { externalNativeBuild { - cmake { - arguments "-DANDROID_ARM_NEON=TRUE", - "-DANDROID_STL=c++_static", - "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" - } + cmake { + arguments "-DCMAKE_BUILD_TYPE=Release" + } } - buildTypes { - release { - externalNativeBuild { - cmake { - arguments "-DCMAKE_BUILD_TYPE=Release" - } - } + def targetPlatforms = project.getProperty('target-platform').split(',') as List + if (!targetPlatforms.isEmpty()) { + def platformAbiMap = [ + 'android-arm64': 'arm64-v8a', + 'android-arm' : 'armeabi-v7a', + 'android-x86' : 'x86', + 'android-x64' : 'x86_64' + ] - def targetPlatforms = project.getProperty('target-platform').split(',') as List - if (!targetPlatforms.isEmpty()) { - // ignore not use abi - def excludeList = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] - - targetPlatforms.each { platform -> - if (platform.equals('android-arm64')) { - excludeList.remove('arm64-v8a') - } - if (platform.equals('android-arm')) { - excludeList.remove('armeabi-v7a') - } - if (platform.equals('android-x86')) { - excludeList.remove('x86') - } - if (platform.equals('android-x64')) { - excludeList.remove('x86_64') - } - } - - println "[OPENCV_CORE] only support platform : $targetPlatforms" - println "[OPENCV_CORE] exclude abi : $excludeList" - packagingOptions { - excludeList.each { - exclude "lib/$it/*" - } - } + def excludeList = platformAbiMap.values() as List + + targetPlatforms.each { platform -> + excludeList.remove(platformAbiMap[platform]) + } + + logger.info "[OPENCV_DART] building for platforms: $targetPlatforms" + logger.info "[OPENCV_DART] excluded abis: $excludeList" + packagingOptions { + excludeList.each { abi -> + exclude "lib/$abi/*" } } + } } } + } }