plugins { // No version: `com.android.application` in :app has already put AGP on the build's plugin // classpath, and Gradle refuses a second request for a version of it ("already on the classpath // with an unknown version"). The version is still the one in the catalog — see libs.versions.toml. id("com.android.test") } /** * The macrobenchmark module: a test APK that instruments the app rather than shipping inside it. * * It has no production code and no build types of its own — it points at `:app`'s `benchmark` build * type through `targetProjectPath` and instruments that. `tools/verify.sh --release` compiles it so * that a rename in the app cannot leave these benchmarks quietly broken between device runs. */ android { namespace = "de.softwareapp_hb.filemanager.benchmark" compileSdk = 36 defaultConfig { minSdk = 26 targetSdk = 36 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } targetProjectPath = ":app" /* * Which variant of :app gets installed and instrumented. * * AGP 9 has no `testBuildType`/`targetVariant` on this plugin — the extension exposes only * `targetProjectPath` — and the target is matched *by name* against this module's own build types. * With just the default `debug` that meant every run installed `app-debug.apk`, whatever else the * build said: the numbers would have been debug numbers. Declaring a `benchmark` build type is what * makes `:benchmark:connectedBenchmarkAndroidTest` instrument `:app`'s benchmark build. * * Setting `testBuildType` in :app instead looks equivalent and is not: there it only moves the * variant that :app's own *unit* tests run against, and `:app:testDebugUnitTest` stops existing. */ buildTypes { create("benchmark") { // A declared build type starts unsigned, and an unsigned test APK fails to install with // INSTALL_PARSE_FAILED_NO_CERTIFICATES. The default type gets the debug key for free; this // borrows the same signing config so the test APK can be installed at all. initWith(getByName("debug")) } } // The benchmark itself is the thing being instrumented: it starts the app under test, so it must // not be run as a normal instrumentation target. experimentalProperties["android.experimental.self-instrumenting"] = true compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } } dependencies { implementation(libs.androidx.benchmark.macro.junit4) implementation(libs.androidx.test.ext.junit) implementation(libs.androidx.test.uiautomator) implementation(libs.androidx.test.runner) }