Skip to content

Commit c6a202a

Browse files
authored
Merge pull request #788 from square/rick/android_convention_plugins
convert Android config scripts to buildSrc convention plugins
2 parents 84bcf72 + 74195ee commit c6a202a

File tree

26 files changed

+140
-109
lines changed

26 files changed

+140
-109
lines changed

.buildscript/android-sample-app.gradle

Lines changed: 0 additions & 11 deletions
This file was deleted.

.buildscript/android-ui-tests.gradle

Lines changed: 0 additions & 17 deletions
This file was deleted.

.buildscript/configure-android-defaults.gradle

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import com.android.build.gradle.TestedExtension
2+
3+
configure<TestedExtension> {
4+
compileSdkVersion(31)
5+
6+
compileOptions {
7+
sourceCompatibility = JavaVersion.VERSION_1_8
8+
targetCompatibility = JavaVersion.VERSION_1_8
9+
}
10+
11+
defaultConfig {
12+
minSdk = 21
13+
targetSdk = 30
14+
versionCode = 1
15+
versionName = "1.0"
16+
}
17+
18+
testOptions {
19+
unitTests {
20+
isReturnDefaultValues = true
21+
isIncludeAndroidResources = true
22+
}
23+
}
24+
25+
buildFeatures.buildConfig = false
26+
27+
// See https://github.com/Kotlin/kotlinx.coroutines/issues/1064#issuecomment-479412940
28+
@Suppress("UnstableApiUsage")
29+
packagingOptions {
30+
resources.excludes.add("META-INF/atomicfu.kotlin_module")
31+
resources.excludes.add("META-INF/common.kotlin_module")
32+
resources.excludes.add("META-INF/android_debug.kotlin_module")
33+
resources.excludes.add("META-INF/android_release.kotlin_module")
34+
resources.excludes.add("META-INF/AL2.0")
35+
resources.excludes.add("META-INF/LGPL2.1")
36+
}
37+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import com.android.build.gradle.TestedExtension
2+
import com.squareup.workflow1.library
3+
import com.squareup.workflow1.libsCatalog
4+
5+
plugins {
6+
id("android-defaults")
7+
}
8+
9+
configure<TestedExtension> {
10+
@Suppress("UnstableApiUsage")
11+
buildFeatures.viewBinding = true
12+
}
13+
14+
dependencies {
15+
"implementation"(project(":workflow-core"))
16+
"implementation"(project(":workflow-runtime"))
17+
18+
"implementation"(libsCatalog.library("androidx-appcompat"))
19+
"implementation"(libsCatalog.library("timber"))
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import com.android.build.gradle.TestedExtension
2+
import com.squareup.workflow1.library
3+
import com.squareup.workflow1.libsCatalog
4+
5+
plugins {
6+
id("android-defaults")
7+
}
8+
9+
configure<TestedExtension> {
10+
defaultConfig {
11+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
12+
testInstrumentationRunnerArguments["listener"] = "leakcanary.FailTestOnLeakRunListener"
13+
}
14+
15+
testOptions {
16+
// Disable transition and rotation animations.
17+
testOptions.animationsDisabled = true
18+
}
19+
}
20+
21+
dependencies {
22+
"androidTestImplementation"(project(":workflow-ui:internal-testing-android"))
23+
24+
"androidTestImplementation"(libsCatalog.library("androidx-test-espresso-core"))
25+
"androidTestImplementation"(libsCatalog.library("androidx-test-junit"))
26+
"androidTestImplementation"(libsCatalog.library("squareup-leakcanary-instrumentation")
27+
)
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.squareup.workflow1
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.artifacts.MinimalExternalModuleDependency
5+
import org.gradle.api.artifacts.VersionCatalog
6+
import org.gradle.api.artifacts.VersionCatalogsExtension
7+
import org.gradle.api.provider.Provider
8+
import org.gradle.kotlin.dsl.getByType
9+
10+
@Suppress("UnstableApiUsage")
11+
val Project.catalogs: VersionCatalogsExtension
12+
get() = extensions.getByType(VersionCatalogsExtension::class)
13+
14+
@Suppress("UnstableApiUsage")
15+
val Project.libsCatalog: VersionCatalog
16+
get() = catalogs.named("libs")
17+
18+
@Suppress("UnstableApiUsage")
19+
fun VersionCatalog.library(alias: String): Provider<MinimalExternalModuleDependency> {
20+
return findLibrary(alias).get()
21+
}

samples/compose-samples/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
plugins {
22
id("com.android.application")
33
`kotlin-android`
4+
`android-sample-app`
5+
`android-ui-tests`
46
}
57

6-
apply(from = rootProject.file(".buildscript/android-sample-app.gradle"))
7-
apply(from = rootProject.file(".buildscript/android-ui-tests.gradle"))
8-
98
android {
109
defaultConfig {
1110
applicationId = "com.squareup.sample.compose"

samples/containers/android/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
plugins {
22
id("com.android.library")
33
`kotlin-android`
4+
`android-defaults`
45
}
56

6-
apply(from = rootProject.file(".buildscript/configure-android-defaults.gradle"))
7-
87
android {
98
defaultConfig {
109
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

samples/containers/app-poetry/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
plugins {
22
id("com.android.application")
33
`kotlin-android`
4+
`android-sample-app`
5+
`android-ui-tests`
46
}
57

6-
apply(from = rootProject.file(".buildscript/android-sample-app.gradle"))
7-
apply(from = rootProject.file(".buildscript/android-ui-tests.gradle"))
8-
98
android {
109
defaultConfig {
1110
applicationId = "com.squareup.sample.containers.poetry"

0 commit comments

Comments
 (0)