jmfayard
10/22/2019, 10:03 AMandroid { ... }
block to a separate file app/android.gradle
- Convert the rest of app/build.gradle
to app/build.gradle.kts
- Add in `app/build.gradle.kts`:
apply(from = "android.gradle")
Example here: https://github.com/jmfayard/update-legacy-android-project/commit/a22c3c4cad4f8db7d562bf7313e23f21b7f7c0d4ribesg
10/22/2019, 10:22 AMjmfayard
10/22/2019, 10:29 AMbuildscript { ... }
syntax
https://plugins.gradle.org/search?term=com.android.applicationbuild.gradle
files is badribesg
10/22/2019, 10:39 AMbuildScript
block in any of my Gradle files in any projectjmfayard
10/22/2019, 10:43 AMmbonnin
10/22/2019, 11:13 AMjmfayard
10/22/2019, 2:54 PM./gradlew :publishPlugins
and that's it.
Here is what my configuration looks like
https://github.com/jmfayard/buildSrcVersions/blob/ec3880ce72f736f30bb6c7bed413c9b67a28e84f/plugin/build.gradle.kts#L3-L33mbonnin
10/22/2019, 3:01 PMjmfayard
10/22/2019, 4:00 PMmbonnin
10/22/2019, 4:19 PMlouiscad
10/22/2019, 9:30 PMefemoney
10/23/2019, 2:41 PMplugins {...}
block.
Overall, I wouldn’t recommend extracting your android {...}
block to a groovy script file and apply. I would stick to using the pluginManagement {...}
block in settings or (my personal fave) declaring the module artifacts as buildSrc
dependencies (effectively making them build script dependencies too). That way you can use the android plugin via plugins {...}
and it works without issues.jmfayard
10/23/2019, 2:58 PMpluginManagement {...}
block.
Please note that it is not a mis-conception but the sad state of things that the Android Gradle Plugin does not currently have Kotlin snippets for documentation.
As you can see in this ticket, it's pretty unique among popular Gradle plugins for this matter.
https://github.com/gradle/gradle/issues/6790
And it's especially infuriating for a number of reasons:
1) AGP is especially complex
2) Lots of Android developers know Android
3) Android Studio is a terrible IDE when the Sync fails
That is the reason for the app/android.gradle
pattern.efemoney
10/23/2019, 3:00 PMjmfayard
10/23/2019, 3:03 PMefemoney
10/23/2019, 3:03 PMeskatos
10/23/2019, 4:03 PMjmfayard
10/23/2019, 7:38 PMmbonnin
10/23/2019, 8:32 PMbuild.gradle.kts
has just landed in AS 4.0 🙌jmfayard
10/23/2019, 9:01 PM// settings.gradle.kts
pluginManagement {
repositories {
google()
jcenter()
gradlePluginPortal()
}
}
mbonnin
10/23/2019, 9:09 PMplugins {
repositories {
google()
jcenter()
gradlePluginPortal()
}
id ("com.android.application) {
artifact("com.android.tools.build:gradle:3.5.0")
apply(false)
}
}
But maybe there's some classpath isolation/class loading constraint I'm missingjmfayard
10/23/2019, 9:11 PMwhat does that mean exactly since the issue is not marked as resolved? https://issuetracker.google.com/issues/64551265has just landed in AS 4.0build.gradle.kts
mbonnin
10/23/2019, 9:11 PMjmfayard
10/23/2019, 9:14 PMmbonnin
10/23/2019, 9:18 PMjmfayard
10/23/2019, 9:20 PMmbonnin
10/23/2019, 9:21 PMplugin {}
syntax if you don't use the generated accessors, you can keep the old buildscript
jmfayard
10/23/2019, 9:24 PMbuild.gradle.kts
with like 50 linesmbonnin
10/23/2019, 9:47 PMandroid {}
was extensions.getByType(BaseExtension::class.java).apply {}
eskatos
10/23/2019, 9:57 PMconfigure<BaseExtension> { .. }
mbonnin
10/23/2019, 9:58 PMjmfayard
10/23/2019, 10:12 PMbuild.gradle.kts
Generate with Cmd-Enter
Open in IntellliJ
Works like a charm
@mbonninmbonnin
10/23/2019, 10:15 PMbuild.gradle.kts
by defaultjmfayard
10/23/2019, 10:18 PMcristiangm
10/31/2019, 11:53 PM