Files
AutoJs6/libs/paddleocr/build.gradle

156 lines
5.5 KiB
Groovy

/**
* Paddle OCR (https://github.com/PaddlePaddle/PaddleOCR) build script (Groovy).
*
* Created by TonyJiangWJ (https://github.com/TonyJiangWJ) on Aug 7, 2023.
* Modified by TonyJiangWJ (https://github.com/TonyJiangWJ) as of Aug 11, 2023.
* Modified by SuperMonster003 as of Sep 4, 2023.
*/
plugins {
id 'org.autojs.build.utils'
id 'org.autojs.build.properties'
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
ext {
projectName = "Paddle OCR"
}
def versionMap = [
"MIN_SDK" : props["MIN_SDK"] as Integer,
"COMPILE_SDK": props["COMPILE_SDK"] as Integer,
"TARGET_SDK" : props["TARGET_SDK"] as Integer,
"NDK" : props["PADDLE_OCR/NDK"],
"CMAKE" : props["PADDLE_OCR/CMAKE"],
"OPENCV" : props["PADDLE_OCR/OPENCV"],
]
def nameMap = [
"PROJECT": ext["projectName"],
"OPENCV" : "OpenCV",
"NDK" : "NDK",
"CMAKE" : "Cmake",
]
def libsToDeploy = [
// @Hint by TonyJiangWJ (https://github.com/TonyJiangWJ) on Aug 7, 2023.
// ! 下载 OpenCV 源码包 (默认为 4.2.0).
// ! 和 Auto.js 中的版本 (如 4.8.0) 不匹配会产生冲突,
// ! 可按需修改 version.properties 中对应内容.
// ! en-US (translated by SuperMonster003 on Oct 22, 2024):
// ! Download the archive for source code of OpenCV (defaults to 4.2.0).
// ! Not matching the version in Auto.js (e.g., 4.8.0) will cause conflicts.
// ! Adjust the corresponding content in version.properties as needed.
utils.newLibDeployer(project, nameMap.OPENCV, "https://github.com/opencv/opencv/releases/download" +
"/${versionMap.OPENCV}/opencv-${versionMap.OPENCV}-android-sdk.zip")
.setSourceDir("/OpenCV-android-sdk/sdk/native/")
.setDestDir("/src/sdk/native/")
]
utils.configureLibraryLifecycleHooks(project, nameMap.PROJECT, [
"OPENCV",
"NDK",
"CMAKE",
].collect { "${nameMap[it]}: ${versionMap[it]}" }, libsToDeploy, "isCleanupPaddleOcr", [".cxx"])
android {
namespace = "com.baidu.paddle.lite.ocr"
ndkVersion versionMap.NDK
compileSdk versionMap.COMPILE_SDK
defaultConfig {
minSdk versionMap.MIN_SDK
targetSdk versionMap.TARGET_SDK
externalNativeBuild {
cmake {
cppFlags(([
"-std": "c++11",
].collect { "$it.key=$it.value" } + [
"-f": ["rtti", "exceptions"],
"-W": "no-format",
].collect {
it.value instanceof List
? it.value.collect { opt -> (it.key + opt) }.join("\u0020")
: it.key + it.value
}).join("\u0020"))
arguments(*[
// @Hint by LZX284 (https://github.com/LZX284) on Sep 30, 2023.
// ! "ANDROID_PLATFORM" 默认为 "android-23", 这里修改为与 AutoJs6 最低 SDK 版本一致的 `versionMap.MIN_SDK`.
// ! en-US (translated by SuperMonster003 on Oct 22, 2024):
// ! "ANDROID_PLATFORM" with default value "android-23" was changed to `versionMap.MIN_SDK`
// ! to align with the min SDK version of AutoJs6.
ANDROID_PLATFORM: "android-${versionMap.MIN_SDK}",
ANDROID_STL : "c++_shared",
ANDROID_ARM_NEON: "TRUE",
].collect {
// @Hint by SuperMonster003 on Nov 12, 2023.
// ! Do not add a space (nbsp) after "-D".
// ! Reference: https://stackoverflow.com/questions/14887438/spacing-in-d-option-in-cmake
// ! zh-CN:
// ! 在 "-D" 后不要添加空格 (不间断空格).
// ! 参阅: https://stackoverflow.com/questions/14887438/spacing-in-d-option-in-cmake
"-D$it.key=$it.value"
})
}
}
ndk {
// @Hint by SuperMonster003 on Jan 2, 2024.
// ! Supported architectures: armv7, armv8.
// ! References:
// ! https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/tools/build_android.sh#L7
// ! https://github.com/PaddlePaddle/Paddle-Lite/issues/80
// ! zh-CN:
// ! 支持的架构: armv7, armv8.
// ! 参阅:
// ! https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/tools/build_android.sh#L7
// ! https://github.com/PaddlePaddle/Paddle-Lite/issues/80
// noinspection ChromeOsAbiSupport
abiFilters "arm64-v8a", "armeabi-v7a"
ldLibs "jnigraphics"
}
}
buildTypes {
release {
minifyEnabled false
}
debug {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility = JavaVersion.toVersion(project.ext.javaVersion)
targetCompatibility = JavaVersion.toVersion(project.ext.javaVersion)
}
kotlinOptions {
jvmTarget = project.ext.javaVersion
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version versionMap.CMAKE
}
}
}
dependencies {
implementation fileTree(include: ["*.jar"], dir: "libs")
implementation project(path: ":libs:org.opencv-${versionMap.OPENCV}")
implementation libs.core.ktx
implementation libs.preference.ktx
}