1/*
2 * Copyright (C) 2020 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 *      http://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/**
18 * This file was created using the `create_project.py` script located in the
19 * `<AndroidX root>/development/project-creator` directory.
20 *
21 * Please use that script when creating a new project, rather than copying an existing project and
22 * modifying its settings.
23 */
24
25import androidx.build.SoftwareType
26import androidx.build.AndroidXConfig
27import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
28
29plugins {
30    id("AndroidXPlugin")
31    id("com.android.library")
32    id("org.jetbrains.kotlin.android")
33}
34
35android {
36    defaultConfig {
37        minSdk = 23
38
39        // We don't care about perf from these correctness tests, so suppress
40        // anything that may otherwise block these tests
41        testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] =
42                "CODE-COVERAGE,DEBUGGABLE,EMULATOR,LOW-BATTERY,UNLOCKED"
43    }
44    sourceSets {
45        main.assets.srcDirs += new File(
46                AndroidXConfig.getPrebuiltsRoot(project),
47                "androidx/traceprocessor/trace_processor_shell"
48        )
49        androidTest.assets.srcDirs += new File(
50                AndroidXConfig.getPrebuiltsRoot(project),
51                "androidx/traceprocessor/testdata"
52        )
53        // PerfettoHandshake supports both AAR and APK as libtracing_perfetto.so sources:
54        // - AAR is used when e.g. tooling downloads tracing-perfetto-binary AAR files from Maven
55        // - APK is when an APK that contains tracing binaries is used
56        //
57        // Adding the AAR as a test asset below allows us to test the AAR scenario
58        androidTest.assets.srcDirs += new File(
59                AndroidXConfig.getPrebuiltsRoot(project),
60                "androidx/internal/androidx/tracing/tracing-perfetto-binary/" +
61                        "${androidx.LibraryVersions.TRACING_PERFETTO}"
62        )
63    }
64
65    namespace = "androidx.benchmark.macro"
66}
67
68dependencies {
69    api(libs.jspecify)
70    api(project(":benchmark:benchmark-common"))
71    api(libs.junit)
72    api(libs.kotlinStdlib)
73    api("androidx.annotation:annotation:1.8.1")
74
75    implementation("androidx.core:core:1.9.0")
76    implementation("androidx.profileinstaller:profileinstaller:1.4.1")
77    implementation("androidx.tracing:tracing-ktx:1.1.0")
78    implementation("androidx.tracing:tracing-perfetto:1.0.0")
79    implementation("androidx.tracing:tracing-perfetto-binary:1.0.0")
80    implementation("androidx.tracing:tracing-perfetto-handshake:1.0.0")
81    implementation("androidx.test:core:1.5.0")
82    implementation(libs.testUiautomator)
83    implementation(libs.wireRuntime)
84    implementation(libs.testExtJunit)
85
86    androidTestImplementation(project(":benchmark:benchmark-junit4"))
87    androidTestImplementation(project(":internal-testutils-ktx"))
88    androidTestImplementation("androidx.activity:activity-ktx:1.3.1")
89    androidTestImplementation(project(":tracing:tracing-perfetto"))
90    androidTestImplementation(libs.testExtJunit)
91    androidTestImplementation(libs.testRules)
92    androidTestImplementation(libs.testRunner)
93    androidTestImplementation(libs.kotlinTest)
94    androidTestImplementation(libs.truth)
95}
96
97androidx {
98    name = "Benchmark - Macrobenchmark"
99    type = SoftwareType.PUBLISHED_LIBRARY
100    inceptionYear = "2020"
101    description = "Android Benchmark - Macrobenchmark"
102    legacyDisableKotlinStrictApiMode = true
103    deviceTests {
104        enableAlsoRunningOnPhysicalDevices = true
105    }
106}
107
108tasks.withType(KotlinCompile).configureEach {
109    kotlinOptions {
110        // Enable using experimental APIs from within same version group
111        freeCompilerArgs += [
112                "-opt-in=androidx.benchmark.ExperimentalBenchmarkConfigApi",
113                "-opt-in=androidx.benchmark.macro.ExperimentalMetricApi",
114                "-opt-in=androidx.benchmark.perfetto.ExperimentalPerfettoCaptureApi",
115                "-opt-in=androidx.benchmark.traceprocessor.ExperimentalTraceProcessorApi",
116                "-opt-in=androidx.benchmark.traceprocessor.ExperimentalInsightApi",
117        ]
118    }
119}
120
121// Define a task dependency so the app is installed before we run macro benchmarks.
122afterEvaluate {
123    // `:benchmark:integration-tests:macrobenchmark-target:installRelease` is not in the compose
124    // build, so it may fail the compose build job.
125    def installTask = tasks.findByPath(
126            ":benchmark:integration-tests:macrobenchmark-target:installRelease")
127    if (installTask != null) {
128        tasks.getByPath(":benchmark:benchmark-macro:connectedReleaseAndroidTest")
129                .dependsOn(installTask)
130    }
131}
132
133androidx {
134    deviceTests {
135        targetAppProject = project(":benchmark:integration-tests:macrobenchmark-target")
136        targetAppVariant = "release"
137    }
138}
139