MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / registerBundleLlamaAssetsTask

Function registerBundleLlamaAssetsTask

app/build.gradle.kts:614–705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612}
613
614fun registerBundleLlamaAssetsTask(
615 flavor: String,
616 arch: String,
617): TaskProvider<Task> {
618 val capitalized =
619 flavor.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() }
620 return tasks.register<Task>("bundle${capitalized}LlamaAssets") {
621 dependsOn("assemble${capitalized}Assets")
622
623 val assetsZipFile = project.layout.buildDirectory.file("outputs/assets/assets-$arch.zip")
624 val outputDir =
625 rootProject.layout.projectDirectory.dir("assets/release/$flavor/dynamic_libs")
626 inputs.file(assetsZipFile)
627 outputs.dir(outputDir)
628
629 doLast {
630 val assetsZip =
631 project.layout.buildDirectory
632 .file("outputs/assets/assets-$arch.zip")
633 .get()
634 .asFile
635 if (!assetsZip.exists()) {
636 throw GradleException("Assets zip not found: ${assetsZip.absolutePath}. Run assemble${capitalized}Assets first.")
637 }
638
639 val tempAar = Files.createTempFile("llama-$flavor", ".aar").toFile()
640 var found = false
641 ZipInputStream(assetsZip.inputStream()).use { zis ->
642 var entry = zis.nextEntry
643 while (entry != null) {
644 if (entry.name == "dynamic_libs/llama.aar") {
645 tempAar.outputStream().use { zis.copyTo(it) }
646 found = true
647 break
648 }
649 entry = zis.nextEntry
650 }
651 }
652
653 if (!found) {
654 tempAar.delete()
655 throw GradleException("dynamic_libs/llama.aar not found inside ${assetsZip.name}")
656 }
657
658 val targetDir = project.rootProject.file("assets/release/$flavor/dynamic_libs")
659 targetDir.mkdirs()
660 val destBr = File(targetDir, "llama-$flavor.aar.br")
661 val destAar = File(targetDir, "llama-$flavor.aar")
662
663 destBr.delete()
664 destAar.delete()
665
666 val brotliAvailable =
667 try {
668 val result =
669 project.exec {
670 commandLine("brotli", "--version")
671 isIgnoreExitValue = true

Callers 1

build.gradle.ktsFile · 0.85

Calls 12

isLowerCaseMethod · 0.80
titlecaseMethod · 0.80
inputStreamMethod · 0.80
toStringMethod · 0.65
registerMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65
fileMethod · 0.45
existsMethod · 0.45
toFileMethod · 0.45
lifecycleMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected