A Gradle plugin that infers Proguard/R8 keep rules for androidTest sources.
Keeper hooks into Proguard/R8 to add extra keep rules based on what androidTest classes use from thetarget app's sources. This is necessary because the Android Gradle Plugin (AGP) does not currentlyfactor in androidTest usages of target app sources when running the minification step, which canresult in runtime errors if APIs used by tests are removed.
Reinvent work at Slack Frontiers Asia Pacific. Enjoy visionary keynotes, on-demand breakout sessions, live roundtables, and more during our free virtual event on May 18. Slack, San Francisco, California. 122,967 likes 87 talking about this. Slack is where work happens. It connects you with the people and apps you work with every day, no matter where you are or what.
This is (really) useful only if you run your instrumentation tests against your minified releasebuilds! If you don't run these tests against minified builds, then you don't need this plugin. Thebuild type that you test against is controlled by the testBuildType
flag, which is set todebug
by default.
This is a workaround until AGP supports this: https://issuetracker.google.com/issues/126429384.
Note: Keeper uses private APIs from AGP and could break between releases. It is currentlytested against AGP version 4.0.0 and 4.1.0-alpha09 (or whatever ci_agp_version
envvars are described here.
Installation¶
Keeper is distributed via Maven Central. Apply the keeper Gradle plugin in your application'sbuild.gradle. Keeper requires Gradle 6.0 or higher.
Keeper can be consumed via regular gradle plugins {}
block.
Note that we still publish to Maven Central, so you would need to add it to the repositories listin settings.gradle
.
Alternatively, it can be consumed via manual buildscript dependency + plugin application.
Note that Keeper must be applied after the Android gradle plugin.
Optional configuration options can be found on the Configuration page.
As of 0.6.0, Keeper requires at least AGP 4.0.0.
Snapshots of the development version are available in Sonatype's snapshots
repository.
Under the hood¶
The general logic flow:
Slackhq Twitter
- Create a custom
r8
configuration for the R8 dependency. - Register two jar tasks per
androidTest
variant. One for all the classes in its targettestedVariant
and one for all the classes in the androidTest variant itself. This will use their variant-providedJavaCompile
tasks andKotlinCompile
tasks if available. - Register a
infer${androidTestVariant}UsageForKeeper
task that plugs the two aforementioned jars into R8'sPrintUses
CLI and outputs the inferred proguard rules into a new intermediate.pro
file. - Finally - the generated file is wired in to Proguard/R8 via private task APIs and setting their
configurationFiles
to include our generated one.
This is (really) useful only if you run your instrumentation tests against your minified releasebuilds! If you don't run these tests against minified builds, then you don't need this plugin. Thebuild type that you test against is controlled by the testBuildType
flag, which is set todebug
by default.
This is a workaround until AGP supports this: https://issuetracker.google.com/issues/126429384.
Note: Keeper uses private APIs from AGP and could break between releases. It is currentlytested against AGP version 4.0.0 and 4.1.0-alpha09 (or whatever ci_agp_version
envvars are described here.
Installation¶
Keeper is distributed via Maven Central. Apply the keeper Gradle plugin in your application'sbuild.gradle. Keeper requires Gradle 6.0 or higher.
Keeper can be consumed via regular gradle plugins {}
block.
Note that we still publish to Maven Central, so you would need to add it to the repositories listin settings.gradle
.
Alternatively, it can be consumed via manual buildscript dependency + plugin application.
Note that Keeper must be applied after the Android gradle plugin.
Optional configuration options can be found on the Configuration page.
As of 0.6.0, Keeper requires at least AGP 4.0.0.
Snapshots of the development version are available in Sonatype's snapshots
repository.
Under the hood¶
The general logic flow:
Slackhq Twitter
- Create a custom
r8
configuration for the R8 dependency. - Register two jar tasks per
androidTest
variant. One for all the classes in its targettestedVariant
and one for all the classes in the androidTest variant itself. This will use their variant-providedJavaCompile
tasks andKotlinCompile
tasks if available. - Register a
infer${androidTestVariant}UsageForKeeper
task that plugs the two aforementioned jars into R8'sPrintUses
CLI and outputs the inferred proguard rules into a new intermediate.pro
file. - Finally - the generated file is wired in to Proguard/R8 via private task APIs and setting their
configurationFiles
to include our generated one.
Slackhq Instagram
Appropriate task dependencies (via inputs/outputs, not dependsOn
) are set up, so this isautomatically run as part of the target app variant's full minified APK.
Slackhammer
The tasks themselves take roughly ~20 seconds total extra work in our Slack android app, with theinfer and app jar tasks each taking around 8-10 seconds and the androidTest jar taking around 2 seconds.