mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
AndroidBuild now working with native Android build.
This commit is contained in:
parent
e8b55882bb
commit
e27b2a5a97
4 changed files with 64 additions and 30 deletions
|
@ -6,7 +6,7 @@ package com.beust.kobalt.api
|
|||
abstract public class ConfigPlugin<T> : BasePlugin() {
|
||||
private val configurations = hashMapOf<String, T>()
|
||||
|
||||
fun configurationFor(project: Project) = configurations[project.name]
|
||||
fun configurationFor(project: Project?) = if (project != null) configurations[project.name] else null
|
||||
|
||||
fun addConfiguration(project: Project, configuration: T) = configurations.put(project.name, configuration)
|
||||
}
|
||||
|
|
|
@ -3,15 +3,18 @@ package com.beust.kobalt.plugin.android
|
|||
import com.android.builder.core.AndroidBuilder
|
||||
import com.android.builder.core.ErrorReporter
|
||||
import com.android.builder.core.LibraryRequest
|
||||
import com.android.builder.dependency.ManifestDependency
|
||||
import com.android.builder.model.SyncIssue
|
||||
import com.android.builder.sdk.DefaultSdkLoader
|
||||
import com.android.builder.sdk.SdkLoader
|
||||
import com.android.ide.common.blame.Message
|
||||
import com.android.ide.common.process.*
|
||||
import com.android.ide.common.res2.*
|
||||
import com.android.manifmerger.ManifestMerger2
|
||||
import com.android.sdklib.repository.FullRevision
|
||||
import com.android.utils.StdLogger
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.Variant
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import java.io.File
|
||||
|
@ -60,27 +63,24 @@ class ProjectLayout {
|
|||
}
|
||||
|
||||
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")
|
||||
// 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() {
|
||||
fun run(project: Project, variant: Variant, config: AndroidConfig) {
|
||||
val logger = StdLogger(StdLogger.Level.VERBOSE)
|
||||
val processExecutor = DefaultProcessExecutor(logger)
|
||||
val javaProcessExecutor = KobaltJavaProcessExecutor()
|
||||
val sdkLoader : SdkLoader = DefaultSdkLoader.getLoader(File("/Users/beust/adt-bundle-mac-x86_64-20140702/sdk"))
|
||||
val repositories = sdkLoader.repositories
|
||||
val sdkInfo = sdkLoader.getSdkInfo(logger)
|
||||
val androidBuilder = AndroidBuilder("com.beust.kobalt", "Cedric Beust",
|
||||
val sdkLoader : SdkLoader = DefaultSdkLoader.getLoader(File(AndroidFiles.androidHome(project, config)))
|
||||
val androidBuilder = AndroidBuilder(project.name, "kobalt-android-plugin",
|
||||
processExecutor,
|
||||
javaProcessExecutor,
|
||||
KobaltErrorReporter(),
|
||||
logger,
|
||||
true /* verbose */)
|
||||
false /* verbose */)
|
||||
|
||||
val processOutputHandler = KobaltProcessOutputHandler()
|
||||
val dir : String = KFiles.joinDir(homeDir("kotlin/kobalt-examples/android-flavors"))
|
||||
val outputDir = KFiles.joinDir(dir, "kobaltBuild", "intermediates", "res", "merged", "pro",
|
||||
"debug")
|
||||
val dir : String = project.directory
|
||||
val outputDir = AndroidFiles.mergedResources(project, variant)
|
||||
val layout = ProjectLayout()
|
||||
val preprocessor = NoOpResourcePreprocessor()
|
||||
|
||||
|
@ -99,15 +99,36 @@ class AndroidBuild {
|
|||
layout.publicText,
|
||||
layout.mergeBlame,
|
||||
preprocessor)
|
||||
println("Repositories: $repositories")
|
||||
val target = androidBuilder.target
|
||||
val dxJar = androidBuilder.dxJar
|
||||
val resourceMerger = ResourceMerger()
|
||||
|
||||
//
|
||||
// Manifest
|
||||
//
|
||||
val mainManifest = File("src/main/AndroidManifest.xml")
|
||||
val manifestOverlays = listOf<File>()
|
||||
val libraries = listOf<ManifestDependency>()
|
||||
val outManifest = AndroidFiles.mergedManifest(project, variant)
|
||||
val outAaptSafeManifestLocation = KFiles.joinDir(project.directory, project.buildDirectory, "generatedSafeAapt")
|
||||
val reportFile = File(KFiles.joinDir(project.directory, project.buildDirectory, "manifest-merger-report.txt"))
|
||||
androidBuilder.mergeManifests(mainManifest, manifestOverlays, libraries,
|
||||
null /* package override */,
|
||||
23 /* versionCode */,
|
||||
"23", /* versionName */
|
||||
"16", /* minSdk */
|
||||
"23" /* targetSdkVersion */,
|
||||
23 /* maxSdkVersion */,
|
||||
outManifest,
|
||||
outAaptSafeManifestLocation,
|
||||
ManifestMerger2.MergeType.APPLICATION,
|
||||
emptyMap(),
|
||||
reportFile)
|
||||
|
||||
//
|
||||
// Resources
|
||||
//
|
||||
listOf("main", "free", "release").forEach {
|
||||
listOf("main", variant.productFlavor.name, variant.buildType.name).forEach {
|
||||
val path = "$dir/src/$it/res"
|
||||
val set = ResourceSet(path)
|
||||
set.addSource(File(path))
|
||||
|
@ -121,6 +142,7 @@ class AndroidBuild {
|
|||
|
||||
|
||||
resourceMerger.mergeData(writer, true)
|
||||
|
||||
println("")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,5 +26,22 @@ class AndroidFiles {
|
|||
|
||||
fun mergedResources(project: Project, variant: Variant) =
|
||||
KFiles.joinAndMakeDir(mergedResourcesNoVariant(project), variant.toIntermediateDir())
|
||||
|
||||
/**
|
||||
* Use the android home define on the project if any, otherwise use the environment variable.
|
||||
*/
|
||||
fun androidHomeNoThrows(project: Project?, config: AndroidConfig): String? {
|
||||
var result = System.getenv("ANDROID_HOME")
|
||||
if (project != null) {
|
||||
if (config.androidHome != null) {
|
||||
result = config.androidHome
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun androidHome(project: Project?, config: AndroidConfig) = androidHomeNoThrows(project, config) ?:
|
||||
throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,19 +66,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
|||
return version as String
|
||||
}
|
||||
|
||||
fun androidHomeNoThrows(project: Project?): String? {
|
||||
var result = System.getenv("ANDROID_HOME")
|
||||
if (project != null) {
|
||||
configurationFor(project)?.androidHome?.let {
|
||||
result = it
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun androidHome(project: Project?) = androidHomeNoThrows(project) ?:
|
||||
throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined")
|
||||
inline fun androidHome(project: Project?) = AndroidFiles.androidHome(project, configurationFor(project)!!)
|
||||
|
||||
fun androidJar(project: Project): Path =
|
||||
Paths.get(androidHome(project), "platforms", "android-${compileSdkVersion(project)}", "android.jar")
|
||||
|
@ -97,10 +85,12 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
|||
runBefore = arrayOf("compile"), runAfter = arrayOf("clean"))
|
||||
fun taskGenerateRFile(project: Project): TaskResult {
|
||||
|
||||
merger.merge(project, context)
|
||||
AndroidBuild().run(project, context.variant, configurationFor(project)!!)
|
||||
// merger.merge(project, context)
|
||||
|
||||
val intermediates = AndroidFiles.intermediates(project)
|
||||
val resDir = "temporaryBogusResDir"
|
||||
val notUsed = ""
|
||||
explodeAarFiles(project, intermediates, File(resDir))
|
||||
val generated = AndroidFiles.generated(project)
|
||||
val success = generateR(project, generated, aapt(project))
|
||||
|
@ -352,7 +342,12 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v
|
|||
|
||||
// IRepoContributor
|
||||
override fun reposFor(project: Project?): List<HostConfig> {
|
||||
val home = androidHomeNoThrows(project)
|
||||
val config = configurationFor(project)
|
||||
var home: String? = null
|
||||
if (config != null) {
|
||||
home = AndroidFiles.androidHomeNoThrows(project, config)
|
||||
}
|
||||
|
||||
return if (home != null) {
|
||||
val path = Paths.get(KFiles.joinDir(home, "extras", "android", "m2repository"))
|
||||
listOf(HostConfig(path.toUri().toString()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue