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 d984b981..493e062d 100644 --- a/packages/opencv_core/android/build.gradle +++ b/packages/opencv_core/android/build.gradle @@ -1,86 +1,110 @@ // 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 { - google() - mavenCentral() - } + 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") - } + 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" +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" - } + cmake { + arguments '-DANDROID_ARM_NEON=TRUE', + '-DANDROID_STL=c++_static', + "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" + } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } + buildTypes { + release { + externalNativeBuild { + cmake { + arguments '-DCMAKE_BUILD_TYPE=Release' + } + } - defaultConfig { - minSdkVersion 24 + 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' + ] - // Invoke the shared CMake build with the Android Gradle Plugin. - externalNativeBuild { - cmake { - arguments "-DANDROID_ARM_NEON=TRUE", - "-DANDROID_STL=c++_static", - "-DCMAKE_INSTALL_PREFIX=$SOURCE_DIR/src/main/jniLibs" + def excludeList = platformAbiMap.values() as List + + targetPlatforms.each { platform -> + excludeList.remove(platformAbiMap[platform]) } - } - buildTypes { - release { - externalNativeBuild { - cmake { - arguments "-DCMAKE_BUILD_TYPE=Release" + 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 997f5fb5..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() - } + 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") - } + 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,59 +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 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/*" } } + } } } + } }