1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Resource merging working.

This commit is contained in:
Cedric Beust 2015-12-04 00:02:01 -08:00
parent 36ee7a4486
commit 69361b1bec
3 changed files with 26 additions and 9 deletions

View file

@ -163,6 +163,12 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
}
}
fun toCamelcaseDir() : String {
val pfName = productFlavor.name
val btName = buildType.name
return pfName[0].toLowerCase() + pfName.substring(1) + btName[0].toUpperCase() + btName.substring(1)
}
fun toIntermediateDir() : String {
if (isDefault) {
return ""

View file

@ -67,7 +67,7 @@ class AndroidBuild {
// val annotationsJar = File("/Users/beust/adt-bundle-mac-x86_64-20140702/sdk/tools/lib/annotations.jar")
// val adb = File("/Users/beust/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb")
fun run(project: Project, variant: Variant, config: AndroidConfig) {
fun run(project: Project, variant: Variant, config: AndroidConfig, aarDependencies: List<File>) {
val logger = StdLogger(StdLogger.Level.VERBOSE)
val processExecutor = DefaultProcessExecutor(logger)
val javaProcessExecutor = KobaltJavaProcessExecutor()
@ -112,7 +112,11 @@ class AndroidBuild {
val mainManifest = File("src/main/AndroidManifest.xml")
val appInfo = AppInfo(mainManifest, config)
val manifestOverlays = listOf<File>()
val manifestOverlays = listOf(
File("src/${variant.productFlavor.name}/AndroidManifest.xml"),
File("src/${variant.buildType.name}/AndroidManifest.xml")).filter {
it.exists()
}
val libraries = listOf<ManifestDependency>()
val outManifest = AndroidFiles.mergedManifest(project, variant)
val outAaptSafeManifestLocation = KFiles.joinDir(project.directory, project.buildDirectory, "generatedSafeAapt")
@ -133,8 +137,12 @@ class AndroidBuild {
//
// Resources
//
listOf("main", variant.productFlavor.name, variant.buildType.name).forEach {
val path = "$dir/src/$it/res"
val fullVariantDir = File(variant.toCamelcaseDir())
val srcList = listOf("main", variant.productFlavor.name, variant.buildType.name, fullVariantDir.path)
.map { "src" + File.separator + it}
val aarList = aarDependencies.map { it.path + File.separator}
(aarList + srcList).map { it + File.separator + "res" }.forEach { path ->
val set = ResourceSet(path)
set.addSource(File(path))
set.loadFromFiles(logger)

View file

@ -85,13 +85,13 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
runBefore = arrayOf("compile"), runAfter = arrayOf("clean"))
fun taskGenerateRFile(project: Project): TaskResult {
AndroidBuild().run(project, context.variant, configurationFor(project)!!)
// merger.merge(project, context)
val intermediates = AndroidFiles.intermediates(project)
val resDir = "temporaryBogusResDir"
val aarDependencies= explodeAarFiles(project, intermediates, File(resDir))
AndroidBuild().run(project, context.variant, configurationFor(project)!!, aarDependencies)
// merger.merge(project, context)
val notUsed = ""
explodeAarFiles(project, intermediates, File(resDir))
val generated = AndroidFiles.generated(project)
val success = generateR(project, generated, aapt(project))
return TaskResult(success)
@ -155,7 +155,8 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
* Extract all the .aar files found in the dependencies and add the android.jar to classpathEntries,
* which will be added to the classpath at compile time
*/
private fun explodeAarFiles(project: Project, outputDir: String, resDir: File) {
private fun explodeAarFiles(project: Project, outputDir: String, resDir: File) : List<File> {
val result = arrayListOf<File>()
project.compileDependencies.filter {
it.jarFile.get().name.endsWith(".aar")
}.forEach {
@ -180,8 +181,10 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
// Copy all the resources from this aar into the same intermediate directory
log(2, "Copying the resources to $resDir")
result.add(destDir)
KFiles.copyRecursively(destDir.resolve("res"), resDir, deleteFirst = false)
}
return result
}
private fun compile(project: Project, rDirectory: String): File {