mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
applicationId fixes and support for androidIdSuffix.
This commit is contained in:
parent
8d8e7cd918
commit
9b011abf7a
2 changed files with 19 additions and 4 deletions
|
@ -3,6 +3,7 @@ package com.beust.kobalt
|
|||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.plugin.android.AndroidConfig
|
||||
import com.beust.kobalt.plugin.android.AndroidPlugin
|
||||
import java.io.File
|
||||
|
||||
|
@ -122,23 +123,35 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
return result
|
||||
}
|
||||
|
||||
fun applicationId(androidConfig: AndroidConfig?): String? {
|
||||
val mainId = productFlavor.applicationId ?: androidConfig?.applicationId
|
||||
val result =
|
||||
if (mainId != null) {
|
||||
mainId + (buildType.applicationIdSuffix ?: "")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
|
||||
* product flavor or main project, and use them to generate any additional field (in that order to
|
||||
* respect the priorities). Return the generated file if it was generated, null otherwise.
|
||||
*/
|
||||
fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
|
||||
val buildConfigs = findBuildConfigs(project, context.variant)
|
||||
val buildConfigs = findBuildConfigs(project, this)
|
||||
|
||||
if (buildConfigs.size > 0) {
|
||||
val androidConfig = (Kobalt.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin)
|
||||
.configurationFor(project)
|
||||
val pkg = androidConfig?.applicationId ?: project.packageName ?: project.group
|
||||
val pkg = applicationId(androidConfig) ?: project.packageName ?: project.group
|
||||
?: throw KobaltException(
|
||||
"packageName needs to be defined on the project in order to generate BuildConfig")
|
||||
|
||||
val code = project.projectInfo.generateBuildConfig(project, context, pkg, context.variant, buildConfigs)
|
||||
val result = KFiles.makeDir(KFiles.generatedSourceDir(project, context.variant, "buildConfig"))
|
||||
val code = project.projectInfo.generateBuildConfig(project, context, pkg, this, buildConfigs)
|
||||
val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig"))
|
||||
// Make sure the generatedSourceDirectory doesn't contain the project.directory since
|
||||
// that directory will be added when trying to find recursively all the sources in it
|
||||
generatedSourceDirectory = File(result.relativeTo(File(project.directory)))
|
||||
|
|
|
@ -181,6 +181,7 @@ interface IBuildConfig {
|
|||
}
|
||||
|
||||
class ProductFlavorConfig(val name: String) : IBuildConfig {
|
||||
var applicationId: String? = null
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
|
@ -192,6 +193,7 @@ fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) =
|
|||
|
||||
class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig {
|
||||
var minifyEnabled = false
|
||||
var applicationIdSuffix: String? = null
|
||||
var proguardFile: String? = null
|
||||
|
||||
fun getDefaultProguardFile(name: String) : String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue