Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void main() {

see [example](https://github.com/rainyl/opencv_dart/tree/main/example)

~~More examples are on the way...~~see [opencv_dart.examples](https://github.com/rainyl/opencv_dart.examples) and share yours
~~More examples are on the way...~~ see [awesome-opencv_dart](https://github.com/rainyl/awesome-opencv_dart) and share yours

### TODO

Expand Down
64 changes: 48 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,70 @@ android {
}

def SOURCE_DIR = project.buildscript.sourceFile.parentFile
def CACHE_DIR = SOURCE_DIR.parentFile
def CVD_VERSION = new File("${project.buildscript.sourceFile.parentFile.parentFile}/binary.version").text
def ROOT_DIR = SOURCE_DIR.parentFile
def CACHE_DIR = new File("${ROOT_DIR}/.dart_tool/.cache")
def CVD_VERSION = new File("${ROOT_DIR}/binary.version").text
def CVD_LIB_URL_BASE = "https://github.com/rainyl/opencv_dart/releases/download"
def ARCHS = ['x86_64', 'arm64-v8a', 'armeabi-v7a']

task downloadLibs(type: Download) {
println "[opencv_dart] Downloading libraries..."
def SRC_URLS = ARCHS.collect { ARCH ->
"${CVD_LIB_URL_BASE}/v${CVD_VERSION}/libopencv_dart-android-${ARCH}.tar.gz"
def ABI_ALL = ['x86_64', 'arm64-v8a', 'armeabi-v7a']
def ABI_ACCEPTED = ['x86_64', 'arm64-v8a', 'armeabi-v7a']

def OPENCV_DART_ANDROID_ENABLED_ABI = System.env.OPENCV_DART_ANDROID_ENABLED_ABI ?: null
if(OPENCV_DART_ANDROID_ENABLED_ABI != null){
println "[opencv_dart] detected OPENCV_DART_ANDROID_ENABLED_ABI: $OPENCV_DART_ANDROID_ENABLED_ABI"
def enabledABI = OPENCV_DART_ANDROID_ENABLED_ABI.split(",")
def acceptedABI = []
enabledABI.each { abi ->
if(ABI_ALL.contains(abi)){
println "[opencv_dart] add abi: ${abi}"
acceptedABI.add(abi)
} else {
println "[opencv_dart] invalid abi: ${abi}, ignored"
}
}
println "[opencv_dart] accepted abi: $acceptedABI"
if (acceptedABI){
ABI_ACCEPTED = acceptedABI
} else {
println "[opencv_dart] invalid OPENCV_DART_ANDROID_ENABLED_ABI: $OPENCV_DART_ANDROID_ENABLED_ABI"
println "[opencv_dart] will enable all supported ABI: $ABI_ACCEPTED"
}
src(SRC_URLS)
dest CACHE_DIR
overwrite false
}

ARCHS.each { arch ->
ABI_ALL.each { arch ->
def extractTaskName = "opencv_dart_extract_libs_${arch}"
def targetDir = new File("${SOURCE_DIR}/src/main/jniLibs/${arch}")
if (targetDir.exists() && !ABI_ACCEPTED.contains(arch)) {
println "[opencv_dart] Deleting libraries for ${arch}..."
delete targetDir
}
task(extractTaskName, type: Copy) {
def targetDir = new File("${SOURCE_DIR}/src/main/jniLibs/${arch}")
onlyIf {
!file("${targetDir}/libopencv_dart.so").exists()
ABI_ACCEPTED.contains(arch) && !file("${targetDir}/libopencv_dart.so").exists()
}
doFirst {
println "[opencv_dart] Extracting libraries for ${arch}..."
}
from tarTree(resources.gzip("${CACHE_DIR}/libopencv_dart-android-${arch}.tar.gz"))
into targetDir
}
}

task downloadLibs(type: Download) {
println "[opencv_dart] Downloading libraries..."
def SRC_URLS = ABI_ACCEPTED.collect { ARCH ->
"${CVD_LIB_URL_BASE}/v${CVD_VERSION}/libopencv_dart-android-${ARCH}.tar.gz"
}
src(SRC_URLS)
dest CACHE_DIR
overwrite false
}

task extractLibs(dependsOn: downloadLibs) {
println "[opencv_dart] Extracting libraries..."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete clean up task, unnecessary extraction and copy will be run if added.

ARCHS.each { arch ->
finalizedBy "opencv_dart_extract_libs_${arch}"
ABI_ALL.each { arch ->
dependsOn "opencv_dart_extract_libs_${arch}"
}

doLast {
println "[opencv_dart] Extract finished."
}
Expand Down