Disable Google Android Instrumentation Test Tracking

Google has started to track Android developers that run instrumentation tests sending all sorts of data about you and your device to Google Analytics. The opt-out solution they give is to add these options to the adb command:

adb shell am instrument -e disableAnalytics true

However, this is not how I typically run my tests. A more convinient and permanent solution is to add the following to your build.gradle file.

android {
defaultConfig {
testInstrumentationRunnerArguments disableAnalytics: 'true'

That’s it. Now the opt-out should work.

I could not find the code of androidx.test.internal.runner.tracker.AnalyticsBasedUsageTracker online, but in case you are interested here’s what they send:

new StringBuilder()
.append(encode(targetPackage, UTF_8))
.append(encode(trackingId, UTF_8))
.append("&v=1") // Protocol Version.
.append("&z=") // Cache Buster (optional)
.append(encode(userId, UTF_8))
.append(encode(screenResolution, UTF_8))
.append(encode(apiLevel, UTF_8))
.append(encode(model, UTF_8))
.append("&t=appview") // Hit type
.append("&sc=start") // Session Control

Comments are closed.