6.7.0 - Alpha6 - Gradle 构建脚本转换 (Groovy -> Kotlin DSL)
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
/**
|
||||
* Rapid OCR (https://github.com/RapidAI/RapidOCR) build script (Groovy).
|
||||
*
|
||||
* Created by SuperMonster003 on Sep 19, 2024.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id 'org.autojs.build.utils'
|
||||
id 'org.autojs.build.properties'
|
||||
id 'org.autojs.build.jvm-convention'
|
||||
id 'com.android.library'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'kotlin-parcelize'
|
||||
}
|
||||
|
||||
ext["projectName"] = "Rapid OCR"
|
||||
|
||||
def versionMap = [
|
||||
"OFFICIAL_NAME" : "1.3.0", /* From original build.gradle file. */
|
||||
"MIN_SDK" : props["MIN_SDK"] as Integer,
|
||||
"COMPILE_SDK" : props["COMPILE_SDK"] as Integer,
|
||||
"TARGET_SDK" : props["TARGET_SDK"] as Integer,
|
||||
"NDK" : props["RAPID_OCR/NDK"],
|
||||
"CMAKE" : props["RAPID_OCR/CMAKE"],
|
||||
"OPENCV_MOBILE" : props["RAPID_OCR/OPENCV_MOBILE"],
|
||||
"OPENCV_MOBILE_LABEL": props["RAPID_OCR/OPENCV_MOBILE_LABEL"],
|
||||
"ONNX" : props["RAPID_OCR/ONNX"],
|
||||
"ONNX_RUNTIME" : props["RAPID_OCR/ONNX_RUNTIME"],
|
||||
]
|
||||
|
||||
def nameMap = [
|
||||
"PROJECT" : ext["projectName"],
|
||||
"OPENCV_MOBILE" : "OpenCV Mobile",
|
||||
"OPENCV_MOBILE_LABEL": "OpenCV Mobile Label",
|
||||
"ONNX" : "Onnx",
|
||||
"ONNX_RUNTIME" : "Onnx Runtime",
|
||||
"NDK" : "NDK",
|
||||
"CMAKE" : "Cmake",
|
||||
]
|
||||
|
||||
def libsToDeploy = [
|
||||
utils.newLibDeployer(project, nameMap.OPENCV_MOBILE, "https://github.com/nihui/opencv-mobile/releases/download" +
|
||||
"/v${versionMap.OPENCV_MOBILE_LABEL}/opencv-mobile-${versionMap.OPENCV_MOBILE}-android.zip")
|
||||
.setSourceDir("/opencv-mobile-${versionMap.OPENCV_MOBILE}-android/sdk/native/")
|
||||
.setDestDir("/src/sdk/native/"),
|
||||
utils.newLibDeployer(project, nameMap.ONNX, "https://github.com/RapidAI/RapidOcrOnnx/releases/download" +
|
||||
"/${versionMap.ONNX}/Project_RapidOcrOnnx-${versionMap.ONNX}.7z")
|
||||
.setSourceDir("/Project_RapidOcrOnnx-${versionMap.ONNX}/models/")
|
||||
.setDestDir("/src/main/assets/models/"),
|
||||
utils.newLibDeployer(project, nameMap.ONNX_RUNTIME, "https://github.com/RapidAI/OnnxruntimeBuilder/releases/download" +
|
||||
"/${versionMap.ONNX_RUNTIME}/onnxruntime-${versionMap.ONNX_RUNTIME}-android-shared.7z")
|
||||
.setSourceDir("/onnxruntime-shared/")
|
||||
.setDestDir("/src/main/onnxruntime-shared/"),
|
||||
]
|
||||
|
||||
utils.configureLibraryLifecycleHooks(project, nameMap.PROJECT, [
|
||||
"OPENCV_MOBILE",
|
||||
"OPENCV_MOBILE_LABEL",
|
||||
"ONNX",
|
||||
"ONNX_RUNTIME",
|
||||
"NDK",
|
||||
"CMAKE",
|
||||
].collect { "${nameMap[it]}: ${versionMap[it]}" }, libsToDeploy, "isCleanupRapidOcr", [".cxx"])
|
||||
|
||||
android {
|
||||
|
||||
namespace = "com.benjaminwan.ocrlibrary"
|
||||
|
||||
ndkVersion versionMap.NDK
|
||||
compileSdk versionMap.COMPILE_SDK
|
||||
|
||||
defaultConfig {
|
||||
minSdk versionMap.MIN_SDK
|
||||
targetSdk versionMap.TARGET_SDK
|
||||
versionName versionMap.OFFICIAL_NAME
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64', 'x86'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
version versionMap.CMAKE
|
||||
}
|
||||
}
|
||||
|
||||
libraryVariants.all {
|
||||
variant ->
|
||||
variant.outputs.all {
|
||||
outputFileName = "${project.name}-${defaultConfig.versionName}-${variant.buildType.name}.aar"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.test.ext.junit
|
||||
androidTestImplementation libs.test.espresso.core
|
||||
|
||||
implementation libs.core.ktx
|
||||
implementation libs.appcompat
|
||||
|
||||
}
|
||||
133
libs/rapidocr/build.gradle.kts
Normal file
133
libs/rapidocr/build.gradle.kts
Normal file
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Rapid OCR (https://github.com/RapidAI/RapidOCR) build script (Kotlin DSL).
|
||||
*
|
||||
* Created by SuperMonster003 on Sep 19, 2024.
|
||||
* Transformed by SuperMonster003 on Sep 30, 2025.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("org.autojs.build.utils")
|
||||
id("org.autojs.build.properties")
|
||||
id("org.autojs.build.jvm-convention")
|
||||
id("com.android.library")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("kotlin-parcelize")
|
||||
}
|
||||
|
||||
ext {
|
||||
set("projectName", "Rapid OCR")
|
||||
}
|
||||
|
||||
val versionMap = mapOf(
|
||||
"OFFICIAL_NAME" to "1.3.0", /* From original build.gradle file. */
|
||||
"MIN_SDK" to props["MIN_SDK"].toInt(),
|
||||
"COMPILE_SDK" to props["COMPILE_SDK"].toInt(),
|
||||
"TARGET_SDK" to props["TARGET_SDK"].toInt(),
|
||||
"NDK" to props["RAPID_OCR/NDK"],
|
||||
"CMAKE" to props["RAPID_OCR/CMAKE"],
|
||||
"OPENCV_MOBILE" to props["RAPID_OCR/OPENCV_MOBILE"],
|
||||
"OPENCV_MOBILE_LABEL" to props["RAPID_OCR/OPENCV_MOBILE_LABEL"],
|
||||
"ONNX" to props["RAPID_OCR/ONNX"],
|
||||
"ONNX_RUNTIME" to props["RAPID_OCR/ONNX_RUNTIME"],
|
||||
)
|
||||
|
||||
val nameMap = mapOf(
|
||||
"PROJECT" to extensions.extraProperties["projectName"] as String,
|
||||
"OPENCV_MOBILE" to "OpenCV Mobile",
|
||||
"OPENCV_MOBILE_LABEL" to "OpenCV Mobile Label",
|
||||
"ONNX" to "Onnx",
|
||||
"ONNX_RUNTIME" to "Onnx Runtime",
|
||||
"NDK" to "NDK",
|
||||
"CMAKE" to "Cmake",
|
||||
)
|
||||
|
||||
val libsToDeploy = listOf(
|
||||
utils.newLibDeployer(
|
||||
project,
|
||||
nameMap["OPENCV_MOBILE"] as String,
|
||||
"https://github.com/nihui/opencv-mobile/releases/download/v${versionMap["OPENCV_MOBILE_LABEL"]}/opencv-mobile-${versionMap["OPENCV_MOBILE"]}-android.zip",
|
||||
).apply {
|
||||
setSourceDir("/opencv-mobile-${versionMap["OPENCV_MOBILE"]}-android/sdk/native/")
|
||||
setDestDir("/src/sdk/native/")
|
||||
},
|
||||
utils.newLibDeployer(
|
||||
project,
|
||||
nameMap["ONNX"] as String,
|
||||
"https://github.com/RapidAI/RapidOcrOnnx/releases/download/${versionMap["ONNX"]}/Project_RapidOcrOnnx-${versionMap["ONNX"]}.7z",
|
||||
).apply {
|
||||
setSourceDir("/Project_RapidOcrOnnx-${versionMap["ONNX"]}/models/")
|
||||
setDestDir("/src/main/assets/models/")
|
||||
},
|
||||
utils.newLibDeployer(
|
||||
project,
|
||||
nameMap["ONNX_RUNTIME"] as String,
|
||||
"https://github.com/RapidAI/OnnxruntimeBuilder/releases/download/${versionMap["ONNX_RUNTIME"]}/onnxruntime-${versionMap["ONNX_RUNTIME"]}-android-shared.7z",
|
||||
).apply {
|
||||
setSourceDir("/onnxruntime-shared/")
|
||||
setDestDir("/src/main/onnxruntime-shared/")
|
||||
},
|
||||
)
|
||||
|
||||
utils.configureLibraryLifecycleHooks(
|
||||
project,
|
||||
nameMap["PROJECT"] as String,
|
||||
listOf("OPENCV_MOBILE", "OPENCV_MOBILE_LABEL", "ONNX", "ONNX_RUNTIME", "NDK", "CMAKE")
|
||||
.map { "${nameMap[it] ?: it}: ${versionMap[it]}" },
|
||||
libsToDeploy,
|
||||
"isCleanupRapidOcr",
|
||||
listOf(".cxx"),
|
||||
)
|
||||
|
||||
android {
|
||||
|
||||
namespace = "com.benjaminwan.ocrlibrary"
|
||||
version = versionMap["OFFICIAL_NAME"] as String
|
||||
|
||||
ndkVersion = versionMap["NDK"] as String
|
||||
compileSdk = versionMap["COMPILE_SDK"] as Int
|
||||
|
||||
defaultConfig {
|
||||
minSdk = versionMap["MIN_SDK"] as Int
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
abiFilters += listOf("armeabi-v7a", "arm64-v8a", "x86_64", "x86")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lint {
|
||||
targetSdk = versionMap["TARGET_SDK"] as Int
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path = file("src/main/cpp/CMakeLists.txt")
|
||||
version = versionMap["CMAKE"] as String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs")))
|
||||
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.test.ext.junit)
|
||||
androidTestImplementation(libs.test.espresso.core)
|
||||
|
||||
implementation(libs.core.ktx)
|
||||
implementation(libs.appcompat)
|
||||
}
|
||||
2
libs/rapidocr/proguard-rules.pro
vendored
2
libs/rapidocr/proguard-rules.pro
vendored
@@ -1,6 +1,6 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
# proguardFiles setting in build.gradle.kts.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
Reference in New Issue
Block a user