6.6.0 - 内置模块重写; 新增部分模块及方法; 修复高版本安卓系统兼容问题; 优化文件管理器及打包功能体验
This commit is contained in:
@@ -1,33 +1,64 @@
|
||||
import java.security.MessageDigest
|
||||
|
||||
/**
|
||||
* PaddleOCR (https://github.com/PaddlePaddle/PaddleOCR) build script (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 "com.android.library"
|
||||
apply {
|
||||
plugin 'com.android.library'
|
||||
plugin 'org.jetbrains.kotlin.android'
|
||||
from '../utils.build.gradle'
|
||||
}
|
||||
|
||||
def versions = new Versions("$rootDir/version.properties")
|
||||
ext {
|
||||
projectName = "Paddle OCR"
|
||||
}
|
||||
|
||||
def versionNdk = versions.ndk
|
||||
def versionCmake = versions.cmake
|
||||
def versions = Utils.newVersions(project)
|
||||
|
||||
def deployer = new LibDeployer(versions.opencv)
|
||||
def versionMap = [
|
||||
"MIN_SDK" : versions["MIN_SDK"] as Integer,
|
||||
"COMPILE_SDK": versions["COMPILE_SDK"] as Integer,
|
||||
"TARGET_SDK" : versions["TARGET_SDK"] as Integer,
|
||||
"NDK" : versions["PADDLE_OCR/NDK"],
|
||||
"CMAKE" : versions["PADDLE_OCR/CMAKE"],
|
||||
"OPENCV" : versions["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/")
|
||||
]
|
||||
|
||||
android {
|
||||
|
||||
namespace = "com.baidu.paddle.lite.ocr"
|
||||
|
||||
ndkVersion versionNdk
|
||||
compileSdk 34
|
||||
ndkVersion versionMap.NDK
|
||||
compileSdk versionMap.COMPILE_SDK
|
||||
|
||||
defaultConfig {
|
||||
/* minSdk 默认为 23,这里修改为与 AutoJs6 最低 SDK 版本一致的 24. */
|
||||
minSdk 24
|
||||
targetSdk 34
|
||||
minSdk versionMap.MIN_SDK
|
||||
targetSdk versionMap.TARGET_SDK
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
@@ -43,8 +74,11 @@ android {
|
||||
}).join("\u0020"))
|
||||
|
||||
arguments(*[
|
||||
// @Hint by LZX284 on Sep 30, 2023.
|
||||
// @Hint by LZX284 (https://github.com/LZX284) on Sep 30, 2023.
|
||||
// ! "ANDROID_PLATFORM" 默认为 "android-23", 这里修改为与 AutoJs6 最低 SDK 版本一致的 24.
|
||||
// ! en-US (translated by SuperMonster003 on Oct 22, 2024):
|
||||
// ! "ANDROID_PLATFORM" with default value "android-23" was changed to 24
|
||||
// ! to align with the min SDK version of AutoJs6.
|
||||
ANDROID_PLATFORM: "android-24",
|
||||
ANDROID_STL : "c++_shared",
|
||||
ANDROID_ARM_NEON: "TRUE",
|
||||
@@ -52,187 +86,87 @@ android {
|
||||
// @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.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.majorVersion
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
version versionCmake
|
||||
version versionMap.CMAKE
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation fileTree(include: ["*.jar"], dir: "libs")
|
||||
implementation project(path: ":libs:org.opencv-${versions.opencv}")
|
||||
implementation "androidx.core:core-ktx:1.12.0"
|
||||
|
||||
implementation project(path: ":libs:org.opencv-${versionMap.OPENCV}")
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.13.1'
|
||||
implementation "androidx.preference:preference-ktx:1.2.1"
|
||||
}
|
||||
|
||||
ext {
|
||||
versions.showInfo()
|
||||
deployer.deploy(project)
|
||||
}
|
||||
|
||||
class LibDeployer {
|
||||
|
||||
String version
|
||||
|
||||
LinkedHashMap<String, String> archive
|
||||
|
||||
LibDeployer(String version) {
|
||||
this.version = version
|
||||
// @Hint by TonyJiangWJ on Aug 7, 2023.
|
||||
// ! 下载 OpenCV 源码包 (默认为 4.2.0).
|
||||
// ! 和 Auto.js 中的版本 (如 4.8.0) 不匹配会产生冲突,
|
||||
// ! 可按需修改 version.properties 中对应内容.
|
||||
this.archive = [
|
||||
"src" : "https://github.com/opencv/opencv/releases/download" +
|
||||
"/$version/opencv-$version-android-sdk.zip",
|
||||
"dest": "OpenCV",
|
||||
]
|
||||
}
|
||||
|
||||
void deploy(Project project) {
|
||||
// Prepare cache folder for archives
|
||||
String cachePath = "cache"
|
||||
if (!project.file(cachePath).exists()) {
|
||||
project.mkdir(cachePath)
|
||||
}
|
||||
def messageDigest = MessageDigest.getInstance("MD5")
|
||||
messageDigest.update(archive.src.bytes)
|
||||
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
|
||||
|
||||
def cacheSrc = archive.src
|
||||
def cacheDest = project.file(new File(cachePath, "${cacheName}.zip"))
|
||||
def libDest = archive.dest
|
||||
def versionNameFileName = "opencv-${version}.version"
|
||||
def versionNameFile = project.file(new File(libDest, versionNameFileName))
|
||||
|
||||
boolean copyFiles = false
|
||||
|
||||
if (cacheDest.exists()) {
|
||||
println("No need to download the OpenCV archive as the cache exists")
|
||||
if (versionNameFile.exists()) {
|
||||
println("No need to extract OpenCV cached archive as the version name file exists")
|
||||
} else {
|
||||
println("OpenCV cached archive needs to be extracted as the version name file doesn't exist")
|
||||
copyFiles = true
|
||||
}
|
||||
println("")
|
||||
} else if (versionNameFile.exists()) {
|
||||
println("No need to download files as the version name file exists")
|
||||
} else {
|
||||
def title = "Downloading the OpenCV archive file including libs and models..."
|
||||
def srcInfo = "Source: ${cacheSrc}"
|
||||
def destInfo = "Destination: ${cacheDest}"
|
||||
def hintInfo = [
|
||||
"If the download gets stuck and won't finish,",
|
||||
"try downloading the source file with tools like IDM (Internet Download Manager),",
|
||||
"then renaming it into the destination path above.",
|
||||
]
|
||||
|
||||
def maxLength = [
|
||||
[title, srcInfo, destInfo].max { it.length() },
|
||||
hintInfo.max { it.length() },
|
||||
].max { it.length() }.length()
|
||||
|
||||
def infoList = [
|
||||
"=".repeat(maxLength),
|
||||
title,
|
||||
"-".repeat(maxLength),
|
||||
srcInfo,
|
||||
destInfo,
|
||||
"-".repeat(maxLength),
|
||||
hintInfo.join("\n"),
|
||||
"=".repeat(maxLength),
|
||||
"",
|
||||
]
|
||||
infoList.forEach { println(it) }
|
||||
|
||||
project.ant.get(src: cacheSrc, dest: cacheDest)
|
||||
|
||||
// Force to copy files from the latest archive files
|
||||
copyFiles = true
|
||||
}
|
||||
|
||||
// Extract the target archive if its dest path does not exists
|
||||
if (copyFiles) {
|
||||
if (project.file(libDest).exists()) {
|
||||
println("Delete old files in \"${project.file(libDest)}\"")
|
||||
project.delete(libDest)
|
||||
}
|
||||
project.copy {
|
||||
from project.zipTree("${cachePath}${File.separator}${cacheName}.zip")
|
||||
into libDest
|
||||
}
|
||||
println("All libs and models extracted into \"${project.file(libDest)}\"")
|
||||
if (!versionNameFile.exists()) {
|
||||
versionNameFile.createNewFile()
|
||||
println("Version name file \"${versionNameFileName}\" created")
|
||||
}
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Versions {
|
||||
|
||||
String opencv
|
||||
String ndk
|
||||
String cmake
|
||||
|
||||
Versions(String filePath) {
|
||||
File file = new File(filePath)
|
||||
if (!file.canRead()) {
|
||||
throw FileNotFoundException("Can't read file '$filePath'")
|
||||
}
|
||||
Properties properties = new Properties()
|
||||
properties.load(new FileInputStream(file))
|
||||
opencv = properties["OPENCV_VERSION"] as String
|
||||
ndk = properties["NDK_VERSION"] as String
|
||||
cmake = properties["CMAKE_VERSION"] as String
|
||||
clean.doFirst {
|
||||
delete project.layout.buildDirectory
|
||||
['.cxx'].forEach { delete file(it) }
|
||||
if (gradle.ext["isCleanupPaddleOcr"] as Boolean) {
|
||||
libsToDeploy.forEach { it.clean() }
|
||||
} else {
|
||||
println("The library files of ${project.ext["projectName"]} won't be cleaned up due to the configuration")
|
||||
}
|
||||
}
|
||||
|
||||
void showInfo() {
|
||||
def title = "Version information for paddleocr library"
|
||||
gradle.taskGraph.whenReady { taskGraph ->
|
||||
if (taskGraph.allTasks.any { it.name == "clean" }) return
|
||||
|
||||
def infoOpenCV = "OpenCV version: $opencv"
|
||||
def infoNdk = "NDK version: $ndk"
|
||||
def infoCmake = "CMake version: $cmake"
|
||||
|
||||
def maxLength = maxOf([title, infoOpenCV, infoNdk, infoCmake].collect { it.length() })
|
||||
|
||||
[
|
||||
"=".repeat(maxLength),
|
||||
title,
|
||||
"-".repeat(maxLength),
|
||||
infoOpenCV,
|
||||
infoNdk,
|
||||
infoCmake,
|
||||
"=".repeat(maxLength),
|
||||
"",
|
||||
].each { println(it) }
|
||||
}
|
||||
|
||||
private static int maxOf(List<Integer> integers) {
|
||||
int max = 0
|
||||
integers.each { max = Math.max(max, it) }
|
||||
return max
|
||||
}
|
||||
Utils.newFormatted("Version information for ${nameMap.PROJECT} library", [
|
||||
"OPENCV",
|
||||
"NDK",
|
||||
"CMAKE",
|
||||
].collect { "${nameMap[it]}: ${versionMap[it]}" }).print()
|
||||
|
||||
libsToDeploy.forEach { it.deploy() }
|
||||
}
|
||||
Reference in New Issue
Block a user