Skip to content

Commit

Permalink
Update AGP to 7.0.4 and GPP to 3.6.0
Browse files Browse the repository at this point in the history
* Migrate to AndroidX test orchestrator
* Enable device storage permission for espresso tests to allow them to
write coverage data
* Factor out espresso test activity management
* Turn off headsup notifications in espresso tests because THEY GET IN THE WAY
* Added RegionsActivityTests
* Moved common espresso tests into tests for both flavours
* Espresso test sharding taken from CircleCI environment directly
* Espresso test leak detection
* Refactor MapLocations to use a LiveData subclass, so that we don't
leak things

Leak detection, refactor map location so that it doesn't leak
  • Loading branch information
growse committed Jan 25, 2022
1 parent dfb1da8 commit 8cd6bd4
Show file tree
Hide file tree
Showing 58 changed files with 1,320 additions and 1,139 deletions.
66 changes: 39 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: 2.1

orbs:
Expand All @@ -8,7 +9,7 @@ jobs:
# These next lines define the Android machine image executor: https://circleci.com/docs/2.0/executor-types/
executor:
name: android/android-docker
tag: 2021.10.2
tag: 2021.12.2
resource-class: large

steps:
Expand All @@ -29,7 +30,7 @@ jobs:
- run:
name: Build
command: |
./project/gradlew -p ./project assembleDebug assembleAndroidTest assembleGmsReleaseUnitTest :app:compileOssReleaseSources :app:packageGmsReleaseBundle --scan
./project/gradlew -p ./project assembleDebug assembleAndroidTest assembleGmsReleaseUnitTest :app:compileOssReleaseSources :app:packageGmsReleaseBundle app:assembleGmsDebugAndroidTest app:assembleOssDebugAndroidTest --scan
- android/save-gradle-cache:
cache-prefix: v3
Expand All @@ -41,7 +42,7 @@ jobs:
fdroid-scanner:
executor:
name: android/android-docker
tag: 2021.10.2
tag: 2021.12.2
resource-class: small
steps:
- checkout
Expand All @@ -55,7 +56,7 @@ jobs:
unit-test:
executor:
name: android/android-docker
tag: 2021.10.2
tag: 2021.12.2
resource-class: large

steps:
Expand All @@ -82,12 +83,12 @@ jobs:
- persist_to_workspace:
root: project/app/build/
paths:
- jacoco/jacoco.xml
- jacoco/jacoco.xml

lint:
executor:
name: android/android-docker
tag: 2021.10.2
tag: 2021.12.2
resource-class: medium+

steps:
Expand Down Expand Up @@ -116,9 +117,11 @@ jobs:
oss-ui-tests:
executor:
name: android/android-machine
tag: 2021.10.1
tag: 2021.12.1
resource-class: large

parallelism: 4
environment:
GRADLE_OPTS: "-Dkotlin.compiler.execution.strategy=in-process"
steps:
- checkout
- android/accept-licenses
Expand All @@ -135,36 +138,41 @@ jobs:
- gradle-v3-
- android/start-emulator-and-run-tests:
additional-avd-args: "-d pixel_3a -c 1G"
additional-emulator-args: "-memory 4096"
test-command: ./gradlew createOssDebugCoverageReport --scan -P"android.testInstrumentationRunnerArguments.numShards=$CIRCLE_NODE_TOTAL" -P"android.testInstrumentationRunnerArguments.shardIndex=$CIRCLE_NODE_INDEX"
additional-emulator-args: "-memory 4096 -cores 3"
test-command: ./gradlew createOssDebugCoverageReport --scan --no-daemon --max-workers 2
system-image: system-images;android-29;default;x86_64
restore-gradle-cache-post-emulator-launch: false
run-tests-working-directory: ./project
post-emulator-wait-steps:
- run: adb shell settings put secure location_providers_allowed +gps
- run: adb shell settings put secure location_providers_allowed +network
- run: adb shell settings put secure location_mode 3
- run: adb shell settings put secure location_providers_allowed +gps && adb shell settings put secure location_providers_allowed +network && adb shell settings put secure location_mode 3 && adb shell settings put global heads_up_notifications_enabled 0 && adb root && sleep 5 && adb shell setprop ctl.restart zygote
- run:
background: true
command: |
adb logcat
name: Logcat
post-emulator-launch-assemble-command: ""
run-logcat: true
max-tries: 1
run-logcat: false
max-tries: 2
no-output-timeout: 30m
save-gradle-cache: false
- store_test_results:
path: project/app/build/outputs/androidTest-results/connected/flavors/oss/
- persist_to_workspace:
root: project/app/build/
paths:
- reports/coverage/oss/debug/report.xml
- reports/coverage/androidTest/oss/debug/report.xml
- store_artifacts:
path: project/app/build/reports/androidTests
destination: espresso-report-oss

gms-ui-tests:
executor:
name: android/android-machine
tag: 2021.10.1
tag: 2021.12.1
resource-class: large
parallelism: 2
parallelism: 4
environment:
GRADLE_OPTS: "-Dkotlin.compiler.execution.strategy=in-process"
steps:
- checkout
- android/accept-licenses
Expand All @@ -181,18 +189,21 @@ jobs:
- gradle-v3-
- android/start-emulator-and-run-tests:
additional-avd-args: "-d pixel_3a -c 1G"
additional-emulator-args: "-memory 4096"
test-command: ./gradlew createGmsDebugCoverageReport --scan -P"android.testInstrumentationRunnerArguments.numShards=$CIRCLE_NODE_TOTAL" -P"android.testInstrumentationRunnerArguments.shardIndex=$CIRCLE_NODE_INDEX"
additional-emulator-args: "-memory 4096 -cores 3"
test-command: ./gradlew createGmsDebugCoverageReport --scan --no-daemon --max-workers 2
system-image: system-images;android-29;google_apis;x86_64
restore-gradle-cache-post-emulator-launch: false
run-tests-working-directory: ./project
post-emulator-wait-steps:
- run: adb shell settings put secure location_providers_allowed +gps
- run: adb shell settings put secure location_providers_allowed +network
- run: adb shell settings put secure location_mode 3
- run: adb shell settings put secure location_providers_allowed +gps && adb shell settings put secure location_providers_allowed +network && adb shell settings put secure location_mode 3 && adb shell settings put global heads_up_notifications_enabled 0 && adb root && sleep 5 && adb shell setprop ctl.restart zygote
- run:
background: true
command: |
adb logcat
name: Logcat
post-emulator-launch-assemble-command: ""
run-logcat: true
max-tries: 1
run-logcat: false
max-tries: 2
no-output-timeout: 30m
save-gradle-cache: false
- run:
Expand All @@ -205,7 +216,7 @@ jobs:
- persist_to_workspace:
root: project/app/build/
paths:
- reports/coverage/gms/debug/report.xml
- reports/coverage/androidTest/gms/debug/report.xml
- store_artifacts:
path: project/app/build/reports/androidTests
destination: espresso-report-gms
Expand Down Expand Up @@ -252,7 +263,7 @@ jobs:
publish-to-play-store:
executor:
name: android/android-docker
tag: 2021.10.2
tag: 2021.12.2
resource-class: medium

steps:
Expand Down Expand Up @@ -314,3 +325,4 @@ workflows:
filters:
branches:
only: master

99 changes: 59 additions & 40 deletions project/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.android.application")
id("dagger.hilt.android.plugin")
id("com.github.triplet.play") version "3.5.0"
id("com.github.triplet.play") version "3.6.0"
kotlin("android")
kotlin("kapt")
id("io.objectbox")
Expand All @@ -20,6 +20,8 @@ jacoco {


val gmsImplementation: Configuration by configurations.creating
val numShards = System.getenv("CIRCLE_NODE_TOTAL") ?: "0"
val shardIndex = System.getenv("CIRCLE_NODE_INDEX") ?: "0"

android {
compileSdk = 31
Expand All @@ -32,23 +34,23 @@ android {
versionCode = 24600
versionName = "2.4.6"

javaCompileOptions {
annotationProcessorOptions {
arguments(mapOf("eventBusIndex" to "org.owntracks.android.EventBusIndex"))
}
}
val locales = listOf("en", "de", "fr", "es", "ru", "ca", "pl", "cs", "ja", "pt", "zh")
buildConfigField(
"String[]",
"TRANSLATION_ARRAY",
"new String[]{\"" + locales.joinToString("\",\"") + "\"}"
)
resConfigs(locales)
testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner")
resourceConfigurations.addAll(locales)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments.putAll(
mapOf(
"clearPackageData" to "false",
"coverageFilePath" to "/storage/emulated/0/coverage"
"clearPackageData" to "true",
"coverage" to "true",
"coverageFilePath" to "/sdcard/coverage/",
"disableAnalytics" to "true",
"useTestStorageService" to "false", // TODO: use this when we get to AGP 7.1
"numShards" to numShards,
"shardIndex" to shardIndex
)
)
}
Expand All @@ -71,9 +73,11 @@ android {
named("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles = mutableListOf(
getDefaultProguardFile("proguard-android.txt"),
file("proguard-rules.pro")
proguardFiles.addAll(
listOf(
getDefaultProguardFile("proguard-android.txt"),
file("proguard-rules.pro")
)
)
resValue("string", "GOOGLE_MAPS_API_KEY", googleMapsAPIKey)
signingConfig = signingConfigs.findByName("release")
Expand All @@ -82,9 +86,11 @@ android {
named("debug") {
isMinifyEnabled = false
isShrinkResources = false
proguardFiles = mutableListOf(
getDefaultProguardFile("proguard-android.txt"),
file("proguard-rules.pro")
proguardFiles.addAll(
listOf(
getDefaultProguardFile("proguard-android.txt"),
file("proguard-rules.pro")
)
)
resValue("string", "GOOGLE_MAPS_API_KEY", googleMapsAPIKey)
applicationIdSuffix = ".debug"
Expand All @@ -97,28 +103,29 @@ android {
viewBinding = true
}

packagingOptions.excludes.addAll(
listOf(
"META-INF/DEPENDENCIES.txt",
"META-INF/LICENSE.txt",
"META-INF/NOTICE.txt",
"META-INF/NOTICE",
"META-INF/LICENSE",
"META-INF/DEPENDENCIES",
"META-INF/notice.txt",
"META-INF/license.txt",
"META-INF/dependencies.txt",
"META-INF/LGPL2.1",
"META-INF/proguard/androidx-annotations.pro",
"META-INF/metadata.kotlin_module",
"META-INF/metadata.jvm.kotlin_module",
"META-INF/gradle/incremental.annotation.processors"
packagingOptions {
resources.excludes.addAll(
listOf(
"META-INF/DEPENDENCIES.txt",
"META-INF/LICENSE.txt",
"META-INF/NOTICE.txt",
"META-INF/NOTICE",
"META-INF/LICENSE",
"META-INF/DEPENDENCIES",
"META-INF/notice.txt",
"META-INF/license.txt",
"META-INF/dependencies.txt",
"META-INF/LGPL2.1",
"META-INF/proguard/androidx-annotations.pro",
"META-INF/metadata.kotlin_module",
"META-INF/metadata.jvm.kotlin_module",
"META-INF/gradle/incremental.annotation.processors"
)
)
)
packagingOptions.jniLibs.useLegacyPackaging = false

jniLibs.useLegacyPackaging = false
}

lintOptions {
lint {
baselineFile = file("../../lint/lint-baseline.xml")
isCheckAllWarnings = true
isWarningsAsErrors = false
Expand All @@ -130,12 +137,16 @@ android {
)
}
testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
animationsDisabled = true
unitTests {
isIncludeAndroidResources = true
isIncludeAndroidResources = true
}
}
testCoverage {
jacocoVersion = rootJacocoVersion
}

tasks.withType<Test> {
testLogging {
Expand All @@ -153,7 +164,7 @@ android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
flavorDimensions("locationProvider")
flavorDimensions.add("locationProvider")
productFlavors {
create("gms") {
dimension = "locationProvider"
Expand All @@ -170,6 +181,9 @@ android {

kapt {
correctErrorTypes = true
arguments {
arg("eventBusIndex", "org.owntracks.android.EventBusIndex")
}
}

tasks.withType<Test> {
Expand Down Expand Up @@ -240,6 +254,8 @@ dependencies {
implementation("com.mikepenz:materialize:1.2.1@aar")
implementation("com.takisoft.preferencex:preferencex:1.1.0")

debugImplementation("com.squareup.leakcanary:leakcanary-android:2.8.1")

// These Java EE libs are no longer included in JDKs, so we include explicitly
kapt("javax.xml.bind:jaxb-api:2.3.1")
kapt("com.sun.xml.bind:jaxb-core:$jaxbVersion")
Expand All @@ -260,21 +276,24 @@ dependencies {
exclude("org.jetbrains.kotlin")
}
androidTestImplementation("com.squareup.okhttp3:mockwebserver:${okHttpVersion}")
androidTestImplementation("com.github.davidepianca98.KMQTT:kmqtt:0.2.9")

androidTestImplementation("androidx.test:rules:${androidxTestVersion}")
androidTestImplementation("androidx.test:runner:${androidxTestVersion}")
androidTestImplementation("com.squareup.leakcanary:leakcanary-android-instrumentation:2.8.1")

androidTestUtil("androidx.test.services:test-services:1.4.1")
androidTestUtil("androidx.test:orchestrator:1.4.1")
}


// Publishing
val serviceAccountCreds = file("owntracks-android-gcloud-creds.json")
val serviceAccountCredentials = file("owntracks-android-gcloud-creds.json")

play {
if (serviceAccountCreds.exists()) {
if (this@Build_gradle.serviceAccountCredentials.exists()) {
enabled.set(true)
serviceAccountCredentials.set(serviceAccountCreds)
serviceAccountCredentials.set(this@Build_gradle.serviceAccountCredentials)
} else {
enabled.set(false)
}
Expand Down
Loading

0 comments on commit 8cd6bd4

Please sign in to comment.