132 lines
3.8 KiB
Groovy
132 lines
3.8 KiB
Groovy
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
plugins {
|
|
id 'com.android.library'
|
|
id 'org.jetbrains.kotlin.android'
|
|
id "com.google.devtools.ksp"
|
|
id "com.diffplug.spotless"
|
|
id "kotlin-parcelize"
|
|
id "org.jetbrains.dokka"
|
|
id "org.mozilla.rust-android-gradle.rust-android"
|
|
}
|
|
|
|
android {
|
|
namespace 'org.oxycblt.musikr'
|
|
compileSdk target_sdk
|
|
ndkVersion "$ndk_version"
|
|
|
|
defaultConfig {
|
|
minSdk min_sdk
|
|
targetSdk target_sdk
|
|
|
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
consumerProguardFiles "consumer-rules.pro"
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
// R8 flips out that random classes were stripped for unknown reasons
|
|
minifyEnabled false
|
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
}
|
|
}
|
|
|
|
compileOptions {
|
|
coreLibraryDesugaringEnabled true
|
|
sourceCompatibility JavaVersion.VERSION_17
|
|
targetCompatibility JavaVersion.VERSION_17
|
|
}
|
|
|
|
kotlinOptions {
|
|
jvmTarget = "17"
|
|
freeCompilerArgs += "-Xjvm-default=all"
|
|
}
|
|
|
|
buildFeatures {
|
|
buildConfig true
|
|
}
|
|
}
|
|
|
|
|
|
cargo {
|
|
module = "./src/main/jni"
|
|
libname = "metadatajni"
|
|
targets = ["arm", "arm64", "x86", "x86_64"]
|
|
prebuiltToolchains = true
|
|
profile = "release"
|
|
}
|
|
|
|
tasks.whenTaskAdded { task ->
|
|
if (task.name == 'mergeDebugJniLibFolders' || task.name == 'mergeReleaseJniLibFolders') {
|
|
task.dependsOn 'cargoBuild'
|
|
}
|
|
for (target in cargo.targets) {
|
|
if (task.name == "cargoBuild${target.capitalize()}") {
|
|
task.dependsOn "copy_libc++_shared${target.capitalize()}"
|
|
}
|
|
}
|
|
}
|
|
|
|
for (target in cargo.targets) {
|
|
tasks.register("copy_libc++_shared${target.capitalize()}", Copy) {
|
|
def ndkDir = android.ndkDirectory
|
|
// hostTag, abi and archTriple from: https://developer.android.com/ndk/guides/other_build_systems
|
|
|
|
def hostTag
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
if (Os.isArch("x86_64") || Os.isArch("amd64")) {
|
|
hostTag = "windows-x86_64"
|
|
} else {
|
|
hostTag = "windows"
|
|
}
|
|
} else if (Os.isFamily(Os.FAMILY_MAC)) {
|
|
hostTag = "darwin-x86_64"
|
|
} else {
|
|
hostTag = "linux-x86_64"
|
|
}
|
|
|
|
def (abi, archTriple) = [
|
|
arm: ['armeabi-v7a', 'arm-linux-androideabi'],
|
|
arm64: ['arm64-v8a', 'aarch64-linux-android'],
|
|
x86: ['x86', 'i686-linux-android'],
|
|
x86_64: ['x86_64', 'x86_64-linux-android'],
|
|
][target]
|
|
|
|
def from_path = "$ndkDir/toolchains/llvm/prebuilt/$hostTag/sysroot/usr/lib/$archTriple/libc++_shared.so"
|
|
def into_path = layout.buildDirectory.dir("rustJniLibs/android/$abi")
|
|
|
|
assert file(from_path).exists()
|
|
|
|
from from_path
|
|
into into_path
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
// Kotlin
|
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
|
|
|
// AndroidX
|
|
implementation "androidx.core:core-ktx:$core_version"
|
|
|
|
// Database
|
|
implementation "androidx.room:room-runtime:$room_version"
|
|
ksp "androidx.room:room-compiler:$room_version"
|
|
implementation "androidx.room:room-ktx:$room_version"
|
|
|
|
// Build
|
|
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugaring_version"
|
|
|
|
// Testing
|
|
testImplementation "junit:junit:4.13.2"
|
|
testImplementation "io.mockk:mockk:1.13.7"
|
|
testImplementation "org.robolectric:robolectric:4.11"
|
|
testImplementation 'androidx.test:core-ktx:1.6.1'
|
|
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
|
}
|
|
|
|
clean {
|
|
delete "$projectDir/build/rustJniLibs"
|
|
}
|