【问题标题】:How to Migrate build.gradle from Groovy to Kotlin DSL in Android Studio Bumblebee?How to Migrate build.gradle from Groovy to Kotlin DSL in Android Studio Bumblebee?
【发布时间】:2022-12-28 01:23:17
【问题描述】:
I want to migrate build.gradle file from Groovy to Kotlin, since I updated my android studio to Bumblebee, I'm not sure how to do it.
This is how build.gradle looks when I create a new project.
I'm not sure on how to migrate plugins{} part.
buildscript {
ext {
compose_version = '1.0.1'
}
}
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.jvm' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
【问题讨论】:
标签:
android
build.gradle
migrate
gradle-kotlin-dsl
【解决方案1】:
I got the answer in the documentation here https://developer.android.com/studio/build#kts.
Here's how it's written in Kotlin.
plugins {
id("com.android.application") version "7.1.0-beta02" apply false
id("com.android.library") version "7.1.0-beta02" apply false
id("org.jetbrains.kotlin.android") version "1.5.30" apply false
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
【解决方案2】:
The following steps worked for me.
Step-1: Create the plugins tag and give it the id values. delete the buildscript tag.
Step-2: Open the pluginManagement tag in the settings.gradle file and make some tags and values.
Step-3: In the last step, update the values defined at the top in the build.gradle file as id.
Optional: Since it is in the build.gradle file, it must be deleted.
repositories {
mavenCentral()
}