Skip to content

Commit 06db993

Browse files
committed
Merge branch 'main' into patch-2
2 parents 42ba433 + d905701 commit 06db993

File tree

16 files changed

+59
-34
lines changed

16 files changed

+59
-34
lines changed

app-nia-catalog/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ android {
4747
missingDimensionStrategy(FlavorDimension.contentType.name, NiaFlavor.demo.name)
4848
}
4949

50-
packagingOptions {
50+
packaging {
5151
resources {
5252
excludes.add("/META-INF/{AL2.0,LGPL2.1}")
5353
}
5454
}
5555
namespace = "com.google.samples.apps.niacatalog"
5656

5757
buildTypes {
58-
val release by getting {
58+
release {
5959
// To publish on the Play store a private signing key is required, but to allow anyone
6060
// who clones the code to sign and run the release variant, use the debug signing key.
6161
// TODO: Abstract the signing configuration to a separate file to avoid hardcoding this.

app/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ android {
3939
}
4040

4141
buildTypes {
42-
val debug by getting {
42+
debug {
4343
applicationIdSuffix = NiaBuildType.DEBUG.applicationIdSuffix
4444
}
4545
val release by getting {
@@ -52,7 +52,7 @@ android {
5252
// TODO: Abstract the signing configuration to a separate file to avoid hardcoding this.
5353
signingConfig = signingConfigs.getByName("debug")
5454
}
55-
val benchmark by creating {
55+
create("benchmark") {
5656
// Enable all the optimizations from release build through initWith(release).
5757
initWith(release)
5858
matchingFallbacks.add("release")
@@ -65,7 +65,7 @@ android {
6565
}
6666
}
6767

68-
packagingOptions {
68+
packaging {
6969
resources {
7070
excludes.add("/META-INF/{AL2.0,LGPL2.1}")
7171
}

benchmarks/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ android {
3939
// This benchmark buildType is used for benchmarking, and should function like your
4040
// release build (for example, with minification on). It's signed with a debug key
4141
// for easy local/CI testing.
42-
val benchmark by creating {
42+
create("benchmark") {
4343
// Keep the build type debuggable so we can attach a debugger if needed.
4444
isDebuggable = true
4545
signingConfig = signingConfigs.getByName("debug")

build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.google.samples.apps.nowinandroid.configureFlavors
2020
import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
2121
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
2222
import com.google.samples.apps.nowinandroid.configurePrintApksTask
23+
import com.google.samples.apps.nowinandroid.disableUnnecessaryAndroidTests
2324
import org.gradle.api.Plugin
2425
import org.gradle.api.Project
2526
import org.gradle.api.artifacts.VersionCatalogsExtension
@@ -44,6 +45,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
4445
}
4546
extensions.configure<LibraryAndroidComponentsExtension> {
4647
configurePrintApksTask(this)
48+
disableUnnecessaryAndroidTests(target)
4749
}
4850
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
4951
configurations.configureEach {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.samples.apps.nowinandroid
18+
19+
import com.android.build.api.variant.LibraryAndroidComponentsExtension
20+
import org.gradle.api.Project
21+
22+
/**
23+
* Disable unnecessary Android instrumented tests for the [project] if there is no `androidTest` folder.
24+
* Otherwise, these projects would be compiled, packaged, installed and ran only to end-up with the following message:
25+
*
26+
* > Starting 0 tests on AVD
27+
*
28+
* Note: this could be improved by checking other potential sourceSets based on buildTypes and flavors.
29+
*/
30+
internal fun LibraryAndroidComponentsExtension.disableUnnecessaryAndroidTests(
31+
project: Project,
32+
) = beforeVariants {
33+
it.enableAndroidTest = it.enableAndroidTest
34+
&& project.projectDir.resolve("src/androidTest").exists()
35+
}

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.android.build.api.dsl.CommonExtension
2020
import com.android.build.api.dsl.ManagedVirtualDevice
2121
import org.gradle.api.Project
2222
import org.gradle.kotlin.dsl.invoke
23-
import java.util.Locale
2423

2524
/**
2625
* Configure project for Gradle managed devices
@@ -55,7 +54,7 @@ private data class DeviceConfig(
5554
val systemImageSource: String,
5655
) {
5756
val taskName = buildString {
58-
append(device.toLowerCase(Locale.ROOT).replace(" ", ""))
57+
append(device.lowercase().replace(" ", ""))
5958
append("api")
6059
append(apiLevel.toString())
6160
append(systemImageSource.replace("-", ""))

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.gradle.kotlin.dsl.withType
2727
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
2828
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
2929
import org.gradle.testing.jacoco.tasks.JacocoReport
30+
import java.util.Locale
3031

3132
private val coverageExclusions = listOf(
3233
// Android
@@ -36,6 +37,10 @@ private val coverageExclusions = listOf(
3637
"**/Manifest*.*"
3738
)
3839

40+
private fun String.capitalize() = replaceFirstChar {
41+
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
42+
}
43+
3944
internal fun Project.configureJacoco(
4045
androidComponentsExtension: AndroidComponentsExtension<*, *, *>,
4146
) {

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ internal fun Project.configureKotlinAndroid(
6262
// Enable experimental coroutines APIs, including Flow
6363
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
6464
"-opt-in=kotlinx.coroutines.FlowPreview",
65-
"-opt-in=kotlin.Experimental",
6665
)
6766
}
6867
}

core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ class TestTopicDao : TopicDao {
5353
return topicEntities.map { it.id.toLong() }
5454
}
5555

56-
override suspend fun updateTopics(entities: List<TopicEntity>) {
57-
throw NotImplementedError("Unused in tests")
58-
}
59-
6056
override suspend fun upsertTopics(entities: List<TopicEntity>) {
6157
// Overwrite old values with new values
6258
entitiesStateFlow.update { oldValues ->

core/database/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed
18-
@Suppress("DSL_SCOPE_VIOLATION")
1917
plugins {
2018
id("nowinandroid.android.library")
2119
id("nowinandroid.android.library.jacoco")

0 commit comments

Comments
 (0)