| 424 | } |
| 425 | |
| 426 | fun createAssetsZip(arch: String) { |
| 427 | val outputDir = |
| 428 | project.layout.buildDirectory |
| 429 | .dir("outputs/assets") |
| 430 | .get() |
| 431 | .asFile |
| 432 | if (!outputDir.exists()) { |
| 433 | outputDir.mkdirs() |
| 434 | } |
| 435 | val zipFile = outputDir.resolve("assets-$arch.zip") |
| 436 | |
| 437 | // --- Part 1: Get the classes.jar from our llama-impl AAR --- |
| 438 | val llamaAarName = |
| 439 | when (arch) { |
| 440 | "arm64-v8a" -> "llama-impl-v8-release.aar" |
| 441 | "armeabi-v7a" -> "llama-impl-v7-release.aar" |
| 442 | else -> throw IllegalArgumentException("Unsupported architecture for Llama AAR: $arch") |
| 443 | } |
| 444 | val originalLlamaAarFile = project.rootDir.resolve("llama-impl/build/outputs/aar/$llamaAarName") |
| 445 | |
| 446 | val tempDir = |
| 447 | project.layout.buildDirectory |
| 448 | .dir("tmp/d8/$arch") |
| 449 | .get() |
| 450 | .asFile |
| 451 | tempDir.deleteRecursively() |
| 452 | tempDir.mkdirs() |
| 453 | val tempClassesJar = File(tempDir, "classes.jar") |
| 454 | |
| 455 | // Extract just the classes.jar from our target AAR |
| 456 | ZipInputStream(originalLlamaAarFile.inputStream()).use { zis -> |
| 457 | var entry = zis.nextEntry |
| 458 | while (entry != null) { |
| 459 | if (entry.name == "classes.jar") { |
| 460 | tempClassesJar.outputStream().use { fos -> zis.copyTo(fos) } |
| 461 | break |
| 462 | } |
| 463 | entry = zis.nextEntry |
| 464 | } |
| 465 | } |
| 466 | if (!tempClassesJar.exists()) { |
| 467 | throw GradleException("classes.jar not found inside ${originalLlamaAarFile.name}") |
| 468 | } |
| 469 | |
| 470 | val llamaImplProject = project.project(":llama-impl") |
| 471 | val flavorName = if (arch == "arm64-v8a") "v8" else "v7" |
| 472 | val configName = "${flavorName}ReleaseRuntimeClasspath" |
| 473 | val runtimeClasspathFiles = llamaImplProject.configurations.getByName(configName).files |
| 474 | |
| 475 | val explodedAarsDir = |
| 476 | project.layout.buildDirectory |
| 477 | .dir("tmp/exploded-aars/$arch") |
| 478 | .get() |
| 479 | .asFile |
| 480 | explodedAarsDir.mkdirs() |
| 481 | |
| 482 | val d8Classpath = mutableListOf<File>() |
| 483 | runtimeClasspathFiles.forEach { file -> |
no test coverage detected