mirror of
https://github.com/android/ndk-samples
synced 2025-11-04 22:53:57 +08:00
Add a (currently trivial) convention plugin.
Apparently gradle's new version catalogs only work in certain contexts, so we still need a convention plugin to be able to centralize decisions like compileSdk and targetSdk. I'm starting with those for now to prove it out, then will expand it to cover other interesting things like NDK version.
This commit is contained in:
11
build-logic/README.md
Normal file
11
build-logic/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Convention plugins
|
||||
|
||||
This directory contains [convention plugins] used by the NDK samples. These are
|
||||
used to remove Gradle boiler plate from individual samples in favor of common
|
||||
configuration here. Using convention plugins for single module projects is
|
||||
overkill, but any non-trivial app will likely need their own eventually. See
|
||||
[Now In Android's build-logic][nia-build-logic] for a more thorough example of
|
||||
building convention plugins for Android projects.
|
||||
|
||||
[convention plugins]: https://docs.gradle.org/current/samples/sample_convention_plugins.html
|
||||
[nia-build-logic]: https://github.com/android/nowinandroid/blob/main/build-logic/README.md
|
||||
31
build-logic/build.gradle.kts
Normal file
31
build-logic/build.gradle.kts
Normal file
@@ -0,0 +1,31 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("java-gradle-plugin")
|
||||
`kotlin-dsl`
|
||||
alias(libs.plugins.jetbrains.kotlin.jvm)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.android.gradlePlugin)
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
register("androidApplication") {
|
||||
id = "ndksamples.android.application"
|
||||
implementationClass = "com.android.ndk.samples.buildlogic.AndroidApplicationConventionPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
13
build-logic/settings.gradle.kts
Normal file
13
build-logic/settings.gradle.kts
Normal file
@@ -0,0 +1,13 @@
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
versionCatalogs {
|
||||
create("libs") {
|
||||
from(files("../gradle/libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "build-logic"
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.android.ndk.samples.buildlogic
|
||||
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
|
||||
class AndroidApplicationConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("com.android.application")
|
||||
}
|
||||
|
||||
extensions.configure<ApplicationExtension> {
|
||||
compileSdk = Versions.COMPILE_SDK
|
||||
defaultConfig {
|
||||
targetSdk = Versions.TARGET_SDK
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.android.ndk.samples.buildlogic
|
||||
|
||||
object Versions {
|
||||
const val COMPILE_SDK = 34
|
||||
const val TARGET_SDK = 34
|
||||
}
|
||||
@@ -6,6 +6,7 @@ junitVersion = "1.1.5"
|
||||
espressoCore = "3.5.1"
|
||||
appcompat = "1.6.1"
|
||||
material = "1.12.0"
|
||||
jetbrainsKotlinJvm = "1.7.21"
|
||||
|
||||
[libraries]
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
@@ -14,7 +15,11 @@ espresso-core = { group = "androidx.test.espresso", name = "espresso-core", vers
|
||||
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||
|
||||
# build-logic dependencies
|
||||
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
||||
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||
jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pluginManagement {
|
||||
includeBuild("build-logic")
|
||||
repositories {
|
||||
google {
|
||||
content {
|
||||
|
||||
Reference in New Issue
Block a user