Wizard: simplify android configuration

This commit is contained in:
Ilya Kirillov
2020-10-09 22:21:00 +03:00
parent 4858b72a8d
commit 733cd8891a
7 changed files with 49 additions and 50 deletions
@@ -64,13 +64,6 @@ android {
defaultConfig {
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName '1.0'
}
buildTypes {
'release' {
minifyEnabled false
}
}
}
@@ -58,13 +58,6 @@ android {
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
@@ -62,12 +62,5 @@ android {
defaultConfig {
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName '1.0'
}
buildTypes {
'release' {
minifyEnabled false
}
}
}
@@ -56,12 +56,5 @@ android {
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
@@ -9,7 +9,12 @@ import java.nio.file.Path
interface AndroidIR : GradleIR
//TODO parematrize
data class AndroidConfigIR(val javaPackage: JavaPackage?, val newManifestPath: Path?) : AndroidIR, FreeIR {
data class AndroidConfigIR(
val javaPackage: JavaPackage?,
val newManifestPath: Path?,
val printVersionCode: Boolean,
val printBuildTypes: Boolean,
) : AndroidIR, FreeIR {
override fun GradlePrinter.renderGradle() {
sectionCall("android", needIndent = true) {
call("compileSdkVersion") { +"29" }; nlIndented() // TODO dehardcode
@@ -29,23 +34,28 @@ data class AndroidConfigIR(val javaPackage: JavaPackage?, val newManifestPath: P
assignmentOrCall("applicationId") { +javaPackage.asCodePackage().quotified }; nlIndented()
}
call("minSdkVersion") { +"24" }; nlIndented() // TODO dehardcode
call("targetSdkVersion") { +"29" }; nlIndented() // TODO dehardcode
assignmentOrCall("versionCode") { +"1" }; nlIndented()
assignmentOrCall("versionName") { +"1.0".quotified }
}
nlIndented()
sectionCall("buildTypes", needIndent = true) {
val sectionIdentifier = when (dsl) {
GradlePrinter.GradleDsl.KOTLIN -> """getByName("release")"""
GradlePrinter.GradleDsl.GROOVY -> "release".quotified
call("targetSdkVersion") { +"29" };// TODO dehardcode
if (printVersionCode) {
nlIndented()
assignmentOrCall("versionCode") { +"1" }; nlIndented()
assignmentOrCall("versionName") { +"1.0".quotified }
}
sectionCall(sectionIdentifier, needIndent = true) {
val minifyCallName = when (dsl) {
GradlePrinter.GradleDsl.KOTLIN -> "isMinifyEnabled"
GradlePrinter.GradleDsl.GROOVY -> "minifyEnabled"
}
if (printBuildTypes) {
nlIndented()
sectionCall("buildTypes", needIndent = true) {
val sectionIdentifier = when (dsl) {
GradlePrinter.GradleDsl.KOTLIN -> """getByName("release")"""
GradlePrinter.GradleDsl.GROOVY -> "release".quotified
}
sectionCall(sectionIdentifier, needIndent = true) {
val minifyCallName = when (dsl) {
GradlePrinter.GradleDsl.KOTLIN -> "isMinifyEnabled"
GradlePrinter.GradleDsl.GROOVY -> "minifyEnabled"
}
assignmentOrCall(minifyCallName) { +"false" }
assignmentOrCall(minifyCallName) { +"false" }
}
}
}
}
@@ -70,13 +70,6 @@ interface AndroidModuleConfigurator : ModuleConfigurator,
+GradleOnlyPluginByNameIR(reader.createAndroidPlugin(module).pluginName, priority = 1)
+GradleOnlyPluginByNameIR("kotlin-android-extensions", priority = 3)
+AndroidConfigIR(
javaPackage = when (reader.createAndroidPlugin(module)) {
AndroidGradlePlugin.APPLICATION -> module.javaPackage(configurationData.pomIr)
AndroidGradlePlugin.LIBRARY -> null
},
newManifestPath = getNewAndroidManifestPath(module)
)
+createRepositories(configurationData.kotlinVersion).map(::RepositoryIR)
}
@@ -203,6 +196,15 @@ object AndroidTargetConfigurator : TargetConfigurator,
buildList {
+super<AndroidModuleConfigurator>.createBuildFileIRs(reader, configurationData, module)
+super<ModuleConfiguratorWithTests>.createBuildFileIRs(reader, configurationData, module)
+AndroidConfigIR(
javaPackage = when (reader.createAndroidPlugin(module)) {
AndroidGradlePlugin.APPLICATION -> module.javaPackage(configurationData.pomIr)
AndroidGradlePlugin.LIBRARY -> null
},
newManifestPath = getNewAndroidManifestPath(module),
printVersionCode = false,
printBuildTypes = false,
)
}
val androidPlugin by enumSetting<AndroidGradlePlugin>(
@@ -11,10 +11,12 @@ import org.jetbrains.kotlin.tools.projectWizard.KotlinNewProjectWizardBundle
import org.jetbrains.kotlin.tools.projectWizard.Versions
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.AndroidConfigIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.BuildScriptDependencyIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.BuildScriptRepositoryIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.irsList
import org.jetbrains.kotlin.tools.projectWizard.library.MavenArtifact
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.AndroidTargetConfigurator.createAndroidPlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GradlePlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModulesToIrConversionData
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
@@ -62,6 +64,19 @@ object AndroidSinglePlatformModuleConfigurator :
}
}
override fun createBuildFileIRs(reader: Reader, configurationData: ModulesToIrConversionData, module: Module) = irsList {
+super<AndroidModuleConfigurator>.createBuildFileIRs(reader, configurationData, module)
+AndroidConfigIR(
javaPackage = when (reader.createAndroidPlugin(module)) {
AndroidGradlePlugin.APPLICATION -> module.javaPackage(configurationData.pomIr)
AndroidGradlePlugin.LIBRARY -> null
},
newManifestPath = getNewAndroidManifestPath(module),
printVersionCode = true,
printBuildTypes = true,
)
}
override fun createKotlinPluginIR(configurationData: ModulesToIrConversionData, module: Module): KotlinBuildSystemPluginIR? =
KotlinBuildSystemPluginIR(
KotlinBuildSystemPluginIR.Type.android,