Closed nagkumar closed 2 years ago
Almost same Issue:
android {
compileSdk 31
defaultConfig {
applicationId "some.name"
minSdk 30
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
was converted to
android {
compileSdk 31
defaultConfig {
applicationId = "some.name"
minSdk 30
targetSdk 31
versionCode 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
...
but should be:
android {
compileSdk = 31
defaultConfig {
applicationId = "some.name"
minSdk = 30
targetSdk = 31
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
...
it can fix by following code. in gradlekotlinconverter.kts
fun String.addEquals(): String {
val compileSdk = "compileSdk"
val signing = "keyAlias|keyPassword|storeFile|storePassword"
val other = "multiDexEnabled|correctErrorTypes|javaMaxHeapSize|jumboMode|dimension|useSupportLibrary"
val databinding = "dataBinding|viewBinding"
val defaultConfig = "applicationId|minSdk|targetSdk|versionCode|versionName|testInstrumentationRunner"
val negativeLookAhead = "(?!\\{)[^\\s]" // Don't want '{' as next word character
val versionExp = """($compileSdk|$defaultConfig|$signing|$other|$databinding)\s*${negativeLookAhead}.*""".toRegex()
return this.replace(versionExp) {
val split = it.value.split(" ")
// if there is more than one whitespace, the last().toIntOrNull() will find.
if (split.lastOrNull { it.isNotBlank() } != null) {
"${split[0]} = ${split.last()}"
} else {
it.value
}
}
}
Thanks @5peak2me! I'll check and integrate your proposal.
above should be converted to