Skip to content

Commit

Permalink
Use new AGP 7 variant APIs + update to AGP 7.1 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers authored Feb 2, 2022
1 parent 8cb608d commit 8340e0c
Show file tree
Hide file tree
Showing 17 changed files with 673 additions and 564 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
strategy:
fail-fast: false # We want to see all results
matrix:
java: [ '11' ]
agp: ['7.0.0', '7.1.0-alpha05']
java: ['11']
agp: ['7.1.0', '7.2.0-beta01']
tracerefs: [true, false]
job: ['instrumentation', 'plugin']
steps:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ buildscript {
mavenCentral()
}

String defaultAgpVersion = "7.0.0"
String defaultAgpVersion = "7.1.0"
String agpVersion = findProperty("keeperTest.agpVersion")?.toString() ?: defaultAgpVersion
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath "com.android.tools.build:gradle:$agpVersion"
classpath "com.slack.keeper:keeper"
}
Expand Down
58 changes: 32 additions & 26 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
Keeper's default behavior with no configuration will enable it for only buildTypes that set
`minifyEnabled` to true. This may not be what you want for your actual production builds that you
plan to distribute.
## Basic Configuration

In order to enable Keeper on a particular variant, you must register the `KeeperVariantMarker`
extension in AGP's `VariantBuilder` API like so:

```kotlin
androidComponents {
beforeVariants { builder ->
if (shouldRunKeeperOnVariant()) {
builder.optInToKeeper() // Helpful extension function
}
}
}
```

Or in Groovy

```kotlin
androidComponents {
beforeVariants { builder ->
if (shouldRunKeeperOnVariant(builder)) {
builder.registerExtension(KeeperVariantMarker.class, KeeperVariantMarker.INSTANCE)
}
}
}
```

Keeper's default behavior with no configuration effectively be a no-op, which isn't what you want!

## Advanced Configuration

Normally, your app variant's minification task doesn't depend on compilation of its corresponding
`androidTest` variant. This means you can call `assembleRelease` and `assembleAndroidTestRelease`
Expand All @@ -9,9 +36,9 @@ Normally, your app variant's minification task doesn't depend on compilation of
you likely _do_ want these "test-only" APIs removed if possible though. There are a few patterns to
better control this behavior via Gradle property.

## Simplest solution
### Simplest solution

The simplest solution is to add a new build type that extends release but is solely used for these
The simplest solution is to add a new build type that extends `release` but is solely used for these
tests. This way it's identical to release in everything except the name.

```groovy
Expand Down Expand Up @@ -69,27 +96,6 @@ if (!hasProperty("productionBuild")) {
}
```

### Variant filter

By default, Keeper will run on any app variant that sets `minifyEnabled` to true.

Alternatively, you can specify a `variantFilter` on the `keeper` extension and dynamically configure
which variants Keeper operates on. This is nearly identical to AGP's native `variantFilter` API except
that there is no `defaultConfig` property.

**Note:** Variants with different `enabled` values will have to be compiled separately. This is common
in most multi-variant projects anyway, but something to be aware of.

```groovy
keeper {
variantFilter {
if (name == "variantThatShouldTotallyBeIgnored") {
setIgnore(true)
}
}
}
```

### <your build here>

Everyone's project is different, so you should do whatever works for you! We're open to suggestions
Expand Down
13 changes: 5 additions & 8 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ result in runtime errors if APIs used by tests are removed.

This is (really) useful _only_ if you run your instrumentation tests against your minified release
builds! If you don't run these tests against minified builds, then you don't need this plugin. The
build type that you test against is controlled by the `testBuildType` flag, which is set to
build type that you test against is controlled by the `testBuildType` flag, which is set to
`debug` 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 currently
tested against AGP version `7.0.0` and `7.1.0-alpha05` (or whatever `ci_agp_version` env
tested against AGP version `7.1.0` and `7.2.0-beta01` (or whatever `ci_agp_version` env
vars are described [here](https://github.com/slackhq/keeper/blob/main/.github/workflows/ci.yml).

## Installation

Keeper is distributed via Maven Central. Apply the keeper Gradle plugin in your application's
build.gradle. Keeper requires Gradle 7.0 or higher.
build.gradle. Keeper requires Gradle 7.0 or higher and AGP 7.1.0 or higher.

Keeper can be consumed via regular gradle `plugins {}` block.

```kotlin
plugins {
id("com.android.application") // <- Keeper only works with com.android.application!
id("com.slack.keeper") version "x.y.z"
}
```
Expand Down Expand Up @@ -58,11 +59,7 @@ apply plugin: "com.android.application" // <- Keeper only works with com.android
apply plugin: "com.slack.keeper"
```

Note that Keeper _must_ be applied after the Android gradle plugin.

Optional configuration options can be found on the [Configuration page](configuration.md).

As of 0.11.0, Keeper requires at least AGP 7.0.0.
Full configuration defaults can be found on the [Configuration page](configuration.md).

Snapshots of the development version are available in [Sonatype's `snapshots` repository][snapshots].

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 8340e0c

Please sign in to comment.