Skip to content

Commit

Permalink
Add R8 shrinker support, update gradle wrapper and android plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
creati8e committed Mar 28, 2019
1 parent ab55102 commit 3cee293
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gradle Plugin that generates randomized dictionaries for proguard

**Tested on latest (3.3) Android Gradle Plugin.**
**Tested on latest (3.3.2) Android Gradle Plugin.**

# How to add
In your root project's `build.gradle`
Expand All @@ -10,7 +10,7 @@ buildscript {
gradlePluginPortal()
dependencies {
classpath "gradle.plugin.ru.cleverpumpkin.proguard-dictionaries-generator:plugin:1.0.1"
classpath "gradle.plugin.ru.cleverpumpkin.proguard-dictionaries-generator:plugin:1.0.2"
}
}
```
Expand Down Expand Up @@ -71,6 +71,11 @@ In your `proguard-rules.pro` file
Plugin runs automatically when android plugin executes proguard task,
so you don't need anything special to get it work.

Also plugin supports R8, new code shrinker. If you'd apply it in
your gradle properties file
(`android.enableR8=true` or `android.enableR8.fullMode=true`),
the plugin will take it in account automatically.

White space, punctuation characters, duplicate words,
and comments after a # sign are ignored in dictionaries by Proguard.
So generated file could contains any symbols except above.
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Versions.projectVer

object Versions {
const val kotlinVer = "1.3.11"
const val projectVer = "1.0.1"
const val projectVer = "1.0.2"
const val androidXVer = "1.0.0"
const val gradlePluginVer = "3.3.0"
const val gradlePluginVer = "3.3.2"
}

object BuildScriptPlugins {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import org.gradle.api.Task
class ProguardDictionaryGeneratorPlugin : Plugin<Project> {

private companion object {
// Task on which we depends on.
// Tasks on which we depends on.
const val TARGET_R8_TASK = "transformClassesAndResourcesWithR8For"
const val TARGET_PROGUARD_TASK = "transformClassesAndResourcesWithProguardFor"

const val LOG_TAG = "ProguardDictionaryGenerator"

val PROP_R8 = listOf("android.enableR8", "android.enableR8.fullMode")
}

override fun apply(project: Project) {
Expand All @@ -33,10 +36,11 @@ class ProguardDictionaryGeneratorPlugin : Plugin<Project> {
private fun Project.setupPlugin() {
val pluginExtension = findPluginExtension()

val proguardTask = findProguardTransformTask()
val targetTaskName = getTargetTaskName()
val proguardTask = findTransformTask(targetTaskName)
if (proguardTask == null) {
logger.lifecycle(
"$LOG_TAG: proguard task ($TARGET_PROGUARD_TASK) not found"
"$LOG_TAG: proguard task ($targetTaskName) not found"
)
return
}
Expand All @@ -59,8 +63,16 @@ class ProguardDictionaryGeneratorPlugin : Plugin<Project> {
proguardTask.dependsOn(createGeneratorTask)
}

private fun Project.findProguardTransformTask(): Task? {
return tasks.find { task -> task.name.startsWith(TARGET_PROGUARD_TASK) }
private fun Project.getTargetTaskName(): String {
return if (isR8Enabled()) TARGET_R8_TASK else TARGET_PROGUARD_TASK
}

private fun Project.isR8Enabled(): Boolean {
return properties.any { (key) -> key in PROP_R8 }
}

private fun Project.findTransformTask(taskName: String): Task? {
return tasks.find { task -> task.name.startsWith(taskName) }
}

private fun Project.findPluginExtension(): ProguardDictionaryPluginExtension {
Expand Down

0 comments on commit 3cee293

Please sign in to comment.