From 3cee293cc7b1bf21a12ba0f7a6cabfd3796a1207 Mon Sep 17 00:00:00 2001 From: Sergey Chuprin Date: Fri, 29 Mar 2019 01:16:51 +0300 Subject: [PATCH] Add R8 shrinker support, update gradle wrapper and android plugin --- README.md | 9 ++++++-- buildSrc/src/main/kotlin/Dependencies.kt | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../ProguardDictionaryGeneratorPlugin.kt | 22 ++++++++++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ad6f7e8..5108a19 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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" } } ``` @@ -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. diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 23e9acb..180e85a 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -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 { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8c65c80..74939a6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-all.zip \ No newline at end of file diff --git a/plugin/src/main/java/ru/cleverpumpkin/plugin/ProguardDictionaryGeneratorPlugin.kt b/plugin/src/main/java/ru/cleverpumpkin/plugin/ProguardDictionaryGeneratorPlugin.kt index 354806e..6dc6fee 100644 --- a/plugin/src/main/java/ru/cleverpumpkin/plugin/ProguardDictionaryGeneratorPlugin.kt +++ b/plugin/src/main/java/ru/cleverpumpkin/plugin/ProguardDictionaryGeneratorPlugin.kt @@ -11,10 +11,13 @@ import org.gradle.api.Task class ProguardDictionaryGeneratorPlugin : Plugin { 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) { @@ -33,10 +36,11 @@ class ProguardDictionaryGeneratorPlugin : Plugin { 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 } @@ -59,8 +63,16 @@ class ProguardDictionaryGeneratorPlugin : Plugin { 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 {