1*7e7863daSAndroid Build Coastguard Worker /*
2*7e7863daSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project
3*7e7863daSAndroid Build Coastguard Worker *
4*7e7863daSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*7e7863daSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*7e7863daSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*7e7863daSAndroid Build Coastguard Worker *
8*7e7863daSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*7e7863daSAndroid Build Coastguard Worker *
10*7e7863daSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*7e7863daSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*7e7863daSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*7e7863daSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*7e7863daSAndroid Build Coastguard Worker * limitations under the License.
15*7e7863daSAndroid Build Coastguard Worker */
16*7e7863daSAndroid Build Coastguard Worker
<lambda>null17*7e7863daSAndroid Build Coastguard Worker plugins {
18*7e7863daSAndroid Build Coastguard Worker alias(libs.plugins.android.test)
19*7e7863daSAndroid Build Coastguard Worker alias(libs.plugins.kotlin.android)
20*7e7863daSAndroid Build Coastguard Worker }
21*7e7863daSAndroid Build Coastguard Worker
<lambda>null22*7e7863daSAndroid Build Coastguard Worker android {
23*7e7863daSAndroid Build Coastguard Worker namespace = "com.google.jetpackcamera.benchmark"
24*7e7863daSAndroid Build Coastguard Worker compileSdk = libs.versions.compileSdk.get().toInt()
25*7e7863daSAndroid Build Coastguard Worker compileSdkPreview = libs.versions.compileSdkPreview.get()
26*7e7863daSAndroid Build Coastguard Worker
27*7e7863daSAndroid Build Coastguard Worker compileOptions {
28*7e7863daSAndroid Build Coastguard Worker sourceCompatibility = JavaVersion.VERSION_1_8
29*7e7863daSAndroid Build Coastguard Worker targetCompatibility = JavaVersion.VERSION_1_8
30*7e7863daSAndroid Build Coastguard Worker }
31*7e7863daSAndroid Build Coastguard Worker
32*7e7863daSAndroid Build Coastguard Worker kotlinOptions {
33*7e7863daSAndroid Build Coastguard Worker jvmTarget = "1.8"
34*7e7863daSAndroid Build Coastguard Worker }
35*7e7863daSAndroid Build Coastguard Worker
36*7e7863daSAndroid Build Coastguard Worker defaultConfig {
37*7e7863daSAndroid Build Coastguard Worker //Our app has a minSDK of 21, but in order for the benchmark tool to function, it must be 23
38*7e7863daSAndroid Build Coastguard Worker minSdk = 23
39*7e7863daSAndroid Build Coastguard Worker targetSdk = libs.versions.targetSdk.get().toInt()
40*7e7863daSAndroid Build Coastguard Worker
41*7e7863daSAndroid Build Coastguard Worker // allows the benchmark to be run on an emulator
42*7e7863daSAndroid Build Coastguard Worker testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] =
43*7e7863daSAndroid Build Coastguard Worker "EMULATOR,LOW-BATTERY,NOT-PROFILEABLE"
44*7e7863daSAndroid Build Coastguard Worker
45*7e7863daSAndroid Build Coastguard Worker testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
46*7e7863daSAndroid Build Coastguard Worker }
47*7e7863daSAndroid Build Coastguard Worker
48*7e7863daSAndroid Build Coastguard Worker buildTypes {
49*7e7863daSAndroid Build Coastguard Worker // This benchmark buildType is used for benchmarking, and should function like your
50*7e7863daSAndroid Build Coastguard Worker // release build (for example, with minification on). It"s signed with a debug key
51*7e7863daSAndroid Build Coastguard Worker // for easy local/CI testing.
52*7e7863daSAndroid Build Coastguard Worker create("benchmark") {
53*7e7863daSAndroid Build Coastguard Worker isDebuggable = true
54*7e7863daSAndroid Build Coastguard Worker signingConfig = getByName("debug").signingConfig
55*7e7863daSAndroid Build Coastguard Worker matchingFallbacks += listOf("release")
56*7e7863daSAndroid Build Coastguard Worker }
57*7e7863daSAndroid Build Coastguard Worker }
58*7e7863daSAndroid Build Coastguard Worker
59*7e7863daSAndroid Build Coastguard Worker flavorDimensions += "flavor"
60*7e7863daSAndroid Build Coastguard Worker productFlavors {
61*7e7863daSAndroid Build Coastguard Worker create("stable") {
62*7e7863daSAndroid Build Coastguard Worker dimension = "flavor"
63*7e7863daSAndroid Build Coastguard Worker }
64*7e7863daSAndroid Build Coastguard Worker
65*7e7863daSAndroid Build Coastguard Worker create("preview") {
66*7e7863daSAndroid Build Coastguard Worker dimension = "flavor"
67*7e7863daSAndroid Build Coastguard Worker targetSdkPreview = libs.versions.targetSdkPreview.get()
68*7e7863daSAndroid Build Coastguard Worker }
69*7e7863daSAndroid Build Coastguard Worker }
70*7e7863daSAndroid Build Coastguard Worker
71*7e7863daSAndroid Build Coastguard Worker targetProjectPath = ":app"
72*7e7863daSAndroid Build Coastguard Worker // required for benchmark:
73*7e7863daSAndroid Build Coastguard Worker // self instrumentation required for the tests to be able to compile, start, or kill the app
74*7e7863daSAndroid Build Coastguard Worker // ensures test and app processes are separate
75*7e7863daSAndroid Build Coastguard Worker // see https://source.android.com/docs/core/tests/development/instr-self-e2e
76*7e7863daSAndroid Build Coastguard Worker experimentalProperties["android.experimental.self-instrumenting"] = true
77*7e7863daSAndroid Build Coastguard Worker }
78*7e7863daSAndroid Build Coastguard Worker
<lambda>null79*7e7863daSAndroid Build Coastguard Worker dependencies {
80*7e7863daSAndroid Build Coastguard Worker implementation(libs.androidx.junit)
81*7e7863daSAndroid Build Coastguard Worker implementation(libs.androidx.benchmark.macro.junit4)
82*7e7863daSAndroid Build Coastguard Worker }
83*7e7863daSAndroid Build Coastguard Worker
84*7e7863daSAndroid Build Coastguard Worker androidComponents {
<lambda>null85*7e7863daSAndroid Build Coastguard Worker beforeVariants(selector().all()) {
86*7e7863daSAndroid Build Coastguard Worker it.enable = it.buildType == "benchmark"
87*7e7863daSAndroid Build Coastguard Worker }
88*7e7863daSAndroid Build Coastguard Worker }