From 73d36d82a3e74f7897d84bb12404792cb8fd24d3 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Fri, 6 Jul 2018 12:15:14 +0100 Subject: [PATCH 1/4] feat: adds a version check for bugsnag-android dependency Adds a version check for the bugsnag-android dependency, and disables writing to proguard files if the version is high enough that consumer proguard rules were added --- .../android/gradle/BugsnagPlugin.groovy | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/com/bugsnag/android/gradle/BugsnagPlugin.groovy b/src/main/groovy/com/bugsnag/android/gradle/BugsnagPlugin.groovy index b620a71d..eef76243 100644 --- a/src/main/groovy/com/bugsnag/android/gradle/BugsnagPlugin.groovy +++ b/src/main/groovy/com/bugsnag/android/gradle/BugsnagPlugin.groovy @@ -10,6 +10,10 @@ import com.android.build.gradle.internal.dsl.BuildType import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.Dependency +import org.gradle.util.VersionNumber + /** * Gradle plugin to automatically upload ProGuard mapping files to Bugsnag. * @@ -30,11 +34,15 @@ class BugsnagPlugin implements Plugin { static final String BUILD_UUID_TAG = 'com.bugsnag.android.BUILD_UUID' static final String GROUP_NAME = 'Bugsnag' + VersionNumber bugsnagVersionNumber + void apply(Project project) { project.extensions.create("bugsnag", BugsnagPluginExtension) project.bugsnag.extensions.create("sourceControl", SourceControl) project.afterEvaluate { + bugsnagVersionNumber = getBugsnagAndroidVersionNumber(project) + project.logger.debug("Using bugsnag-android version number: $bugsnagVersionNumber") // Make sure the android plugin has been applied first if (project.plugins.hasPlugin(AppPlugin)) { @@ -55,6 +63,26 @@ class BugsnagPlugin implements Plugin { } } + /** + * Retrieves the VersionNumber used by com.bugsnag.android in the given project. This can be used + * to conditionally perform tasks depending on the artefact version. + */ + static VersionNumber getBugsnagAndroidVersionNumber(Project project) { + List configs = project.configurations.collect() + List deps = configs.stream() + .map { conf -> conf.allDependencies } + .collect() + .flatten() + + def bugsnagVersion = deps.stream() + .filter { dep -> return dep.group == "com.bugsnag" && dep.name == "bugsnag-android" } + .distinct() + .map({ dep -> return dep.version }) + .findFirst() + + return bugsnagVersion.present ? VersionNumber.parse(bugsnagVersion.get()) : VersionNumber.UNKNOWN + } + private static void setupNdkProject(Project project) { def cleanTasks = project.tasks.findAll { it.name.startsWith("externalNative") && it.name.contains("Clean") @@ -76,7 +104,7 @@ class BugsnagPlugin implements Plugin { * Create tasks for each Build Variant * See https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Build-Variants */ - private static void applyBugsnagToVariant(BaseVariant variant, Project project) { + private void applyBugsnagToVariant(BaseVariant variant, Project project) { if (hasDisabledBugsnag(variant)) { return } @@ -213,14 +241,19 @@ class BugsnagPlugin implements Plugin { * task is named `transformClassesAndResourcesWithProguardForRelease` * as it is now part of the "transforms" process. */ - private static void setupProguardAutoConfig(Project project, BaseVariant variant) { + private void setupProguardAutoConfig(Project project, BaseVariant variant) { BugsnagProguardConfigTask proguardConfigTask = project.tasks.create("processBugsnag${taskNameForVariant(variant)}Proguard", BugsnagProguardConfigTask) proguardConfigTask.group = GROUP_NAME proguardConfigTask.variant = variant - if (project.bugsnag.autoProguardConfig) { + // consumer proguard rules were added to the library in 4.6.0 + boolean hasConsumerRules = bugsnagVersionNumber.major >= 4 && bugsnagVersionNumber.minor >= 6 + + if (project.bugsnag.autoProguardConfig && !hasConsumerRules) { project.logger.debug("Bugsnag autoproguard config enabled") dependTaskOnPackageTask(variant, proguardConfigTask) + } else { + project.logger.debug("ProGuard has consumer rules, skipping write") } } From 5e3f814c5fc462f513452a865c24cfbc862bf61b Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Fri, 6 Jul 2018 12:19:45 +0100 Subject: [PATCH 2/4] docs: add changelog entry for disabling proguard --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3109a0d5..846d562d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ + +## 3.2.8 (2018-06-21) + +### Bug fixes + +* Add a version check for bugsnag-android dependency, disabling redundant ProGuard config if >= v4.6.0 +[Jamie Lynch](https://github.com/fractalwrench) [#116](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/116) + ## 3.2.8 (2018-06-21) ### Bug fixes From be5887a40e23b7fbd0c2985fc40df5d2ac07b152 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Fri, 6 Jul 2018 15:30:37 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 846d562d..c42d7fc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -## 3.2.8 (2018-06-21) +## 3.2.8 (TBD) ### Bug fixes From 8b78ee4ebb7b7ec1bbc1ae0a4d149f7d4f4c9eb9 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Fri, 6 Jul 2018 15:32:01 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c42d7fc9..38c36a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -## 3.2.8 (TBD) +## 3.3.0 (TBD) ### Bug fixes