Convert gradle to kotlin script

Its more idiomatic & JVM like compared Groovy.

Also is the new standard.
This commit is contained in:
clocks 2024-07-22 13:54:00 -04:00
parent 7159767364
commit ad0e0f4434
No known key found for this signature in database
GPG Key ID: DF550F49A97F8A4B
8 changed files with 238 additions and 229 deletions

View File

@ -1,32 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
ext {
tesseract4AndroidVersion = '4.7.0'
}
task clean(type: Delete) {
delete rootProject.buildDir
}

30
build.gradle.kts Normal file
View File

@ -0,0 +1,30 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
mavenCentral()
maven("https://jitpack.io")
}
}
val tesseract4AndroidVersion by ext("4.7.0")
tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
}

View File

@ -1,70 +0,0 @@
plugins {
id 'com.android.application'
}
android {
namespace 'cz.adaptech.tesseract4android.sample'
compileSdk 34
defaultConfig {
applicationId "cz.adaptech.tesseract4android.sample"
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
buildFeatures {
viewBinding true
}
}
// In case you are using dependency on local library (the project(':tesseract4android') below),
// uncomment this to specify which flavor you want to build.
// Or you can specify *same* flavors also for the app - then they will be matched automatically.
// See more: https://developer.android.com/studio/build/build-variants#variant_aware
/*android {
defaultConfig {
// Choose 'standard' or 'openmp' flavor of the library
missingDimensionStrategy 'parallelization', 'standard'
}
flavorDimensions = ['parallelization']
}*/
dependencies {
// To use library from JitPack
// Note that since we have 2 artifacts, we must use cz.adaptech.tesseract4android groupId,
// instead of just cz.adaptech groupId we use when using local maven repository.
implementation "cz.adaptech.tesseract4android:tesseract4android:$tesseract4AndroidVersion" // standard flavor
// implementation "cz.adaptech.tesseract4android:tesseract4android-openmp:$tesseract4AndroidVersion" // openmp flavor
// To use library from local maven repository
// Don't forget to specify mavenLocal() in repositories block in project's build.gradle file
// implementation "cz.adaptech:tesseract4android:$tesseract4AndroidVersion" // standard flavor
// implementation "cz.adaptech:tesseract4android-openmp:$tesseract4AndroidVersion" // openmp flavor
// To use library compiled locally
// Which flavor to use is determined by missingDimensionStrategy parameter above.
// implementation project(':tesseract4android')
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata:2.7.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.7.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

76
sample/build.gradle.kts Normal file
View File

@ -0,0 +1,76 @@
plugins {
id("com.android.application")
}
android {
namespace = "cz.adaptech.tesseract4android.sample"
compileSdk = 34
defaultConfig {
applicationId = "cz.adaptech.tesseract4android.sample"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
viewBinding = true
}
}
// In case you are using dependency on local library (the project(":tesseract4android") below),
// uncomment this to specify which flavor you want to build.
// Or you can specify *same* flavors also for the app - then they will be matched automatically.
// See more: https://developer.android.com/studio/build/build-variants#variant_aware
/*android {
defaultConfig {
// Choose "standard" or "openmp" flavor of the library
missingDimensionStrategy "parallelization", "standard"
}
flavorDimensions = ["parallelization"]
}*/
val tesseract4AndroidVersion: String by rootProject.extra
dependencies {
// To use library from JitPack
// Note that since we have 2 artifacts, we must use cz.adaptech.tesseract4android groupId,
// instead of just cz.adaptech groupId we use when using local maven repository.
implementation("cz.adaptech.tesseract4android:tesseract4android:$tesseract4AndroidVersion")
// standard flavor
// implementation "cz.adaptech.tesseract4android:tesseract4android-openmp:$tesseract4AndroidVersion" // openmp flavor
// To use library from local maven repository
// Don't forget to specify mavenLocal() in repositories block in project's build.gradle file
// implementation "cz.adaptech:tesseract4android:$tesseract4AndroidVersion" // standard flavor
// implementation "cz.adaptech:tesseract4android-openmp:$tesseract4AndroidVersion" // openmp flavor
// To use library compiled locally
// Which flavor to use is determined by missingDimensionStrategy parameter above.
// implementation project(":tesseract4android")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.lifecycle:lifecycle-livedata:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel:2.7.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

View File

@ -1,4 +0,0 @@
include ':tesseract4android'
if (!System.env.JITPACK) {
include ':sample'
}

4
settings.gradle.kts Normal file
View File

@ -0,0 +1,4 @@
include(":tesseract4android")
if (System.getenv("JITPACK") == null) {
include(":sample")
}

View File

@ -1,123 +0,0 @@
plugins {
id 'com.android.library'
id 'maven-publish'
}
android {
namespace 'cz.adaptech.tesseract4android'
compileSdk 33
ndkVersion "25.1.8937393"
defaultConfig {
minSdk 16
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
// Specifies which native libraries or executables to build and package.
// TODO: Include eyes-two in some build flavor of the library?
//targets "jpeg", "pngx", "leptonica", "tesseract"
}
}
ndk {
// Specify the ABI configurations that Gradle should build and package.
// By default it compiles all available ABIs.
//abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version '3.22.1'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
externalNativeBuild {
cmake {
// Force building release version of native libraries even in debug variant.
// This is for projects that has direct dependency on this library,
// but doesn't really want its debug version, which is very slow.
// Note that this only affects native code.
arguments "-DCMAKE_BUILD_TYPE=Release"
}
}
}
}
flavorDimensions = ["parallelization"]
productFlavors {
standard {
}
openmp {
externalNativeBuild {
cmake {
// NOTE: We must add -static-openmp argument to build it statically,
// because shared library is not being included in the resulting APK.
// See: https://github.com/android/ndk/issues/1028
// Use of that argument shows warnings during build:
// > C/C++: clang: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
// But it has no effect on the result.
cFlags "-fopenmp -static-openmp -Wno-unused-command-line-argument"
cppFlags "-fopenmp -static-openmp -Wno-unused-command-line-argument"
}
}
}
}
publishing {
singleVariant("standardRelease") {
withSourcesJar()
withJavadocJar()
}
singleVariant("openmpRelease") {
withSourcesJar()
withJavadocJar()
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
buildFeatures {
buildConfig true
}
}
dependencies {
// Intentionally use old version of annotation library which doesn't depend on kotlin-stdlib
// to not unnecessarily complicate client projects due to potential duplicate class build errors
// caused by https://kotlinlang.org/docs/whatsnew18.html#updated-jvm-compilation-target
//noinspection GradleDependency
implementation 'androidx.annotation:annotation:1.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
afterEvaluate {
publishing {
publications {
standard(MavenPublication) {
from components.findByName('standardRelease')
groupId 'cz.adaptech'
artifactId 'tesseract4android'
version rootProject.ext.tesseract4AndroidVersion
}
openmp(MavenPublication) {
from components.findByName('openmpRelease')
groupId 'cz.adaptech'
artifactId 'tesseract4android-openmp'
version rootProject.ext.tesseract4AndroidVersion
}
}
}
}

View File

@ -0,0 +1,128 @@
plugins {
id("com.android.library")
id("maven-publish")
}
android {
namespace = "cz.adaptech.tesseract4android"
compileSdk = 33
ndkVersion = "25.1.8937393"
defaultConfig {
minSdk = 16
lint.targetSdk = 33
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
// Specifies which native libraries or executables to build and package.
// TODO: Include eyes-two in some build flavor of the library?
//targets "jpeg", "pngx", "leptonica", "tesseract"
}
}
ndk {
// Specify the ABI configurations that Gradle should build and package.
// By default it compiles all available ABIs.
//abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
}
}
externalNativeBuild {
cmake {
path("src/main/cpp/CMakeLists.txt")
version = "3.22.1"
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
debug {
externalNativeBuild {
cmake {
// Force building release version of native libraries even in debug variant.
// This is for projects that has direct dependency on this library,
// but doesn"t really want its debug version, which is very slow.
// Note that this only affects native code.
arguments("-DCMAKE_BUILD_TYPE=Release")
}
}
}
}
flavorDimensions += listOf("parallelization")
productFlavors {
create("standard") {
}
create("openmp") {
externalNativeBuild {
cmake {
// NOTE: We must add -static-openmp argument to build it statically,
// because shared library is not being included in the resulting APK.
// See: https://github.com/android/ndk/issues/1028
// Use of that argument shows warnings during build:
// > C/C++: clang: warning: argument unused during compilation: "-static-openmp" [-Wunused-command-line-argument]
// But it has no effect on the result.
cFlags("-fopenmp -static-openmp -Wno-unused-command-line-argument")
cppFlags("-fopenmp -static-openmp -Wno-unused-command-line-argument")
}
}
}
}
publishing {
singleVariant("standardRelease") {
withSourcesJar()
withJavadocJar()
}
singleVariant("openmpRelease") {
withSourcesJar()
withJavadocJar()
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
buildConfig = true
}
}
dependencies {
// Intentionally use old version of annotation library which doesn"t depend on kotlin-stdlib
// to not unnecessarily complicate client projects due to potential duplicate class build errors
// caused by https://kotlinlang.org/docs/whatsnew18.html#updated-jvm-compilation-target
//noinspection GradleDependency
implementation("androidx.annotation:annotation:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test:runner:1.5.2")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
val tesseract4AndroidVersion: String by rootProject.extra
afterEvaluate {
publishing {
publications {
create<MavenPublication>("standard") {
from(components.findByName("standardRelease"))
groupId = "cz.adaptech"
artifactId = "tesseract4android"
version = tesseract4AndroidVersion
}
create<MavenPublication>("openmp") {
from(components.findByName("openmpRelease"))
groupId = "cz.adaptech"
artifactId = "tesseract4android-openmp"
version = tesseract4AndroidVersion
}
}
}
}