From 7a9572f48943e4d8127e7b6d94328daf1605fdc6 Mon Sep 17 00:00:00 2001 From: hedex Date: Wed, 11 Apr 2018 16:01:49 +0800 Subject: [PATCH] fix gradle 3.1 bug Signed-off-by: hedex --- .../gradle/plugin/RobustApkHashAction.groovy | 23 ++++++++++++++++++- gradle.properties | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy b/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy index 2d876d0c..32fa366e 100755 --- a/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy +++ b/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy @@ -204,11 +204,32 @@ class RobustApkHashAction implements Action { public static boolean isGradlePlugin300orAbove() { try { - String gradlePluginVersion = com.android.builder.Version.ANDROID_GRADLE_PLUGIN_VERSION + String gradlePluginVersion = getGradlePluginVersion() return gradlePluginVersion.compareTo("3.0.0") >= 0; } catch (Throwable throwable) { } return false; } + + static String getGradlePluginVersion() { + String version = null + try { + def clazz = Class.forName("com.android.builder.Version") + def field = clazz.getDeclaredField("ANDROID_GRADLE_PLUGIN_VERSION") + field.setAccessible(true) + version = field.get(null) + } catch (Exception ignore) { + } + if (version == null) { + try { + def clazz = Class.forName("com.android.builder.model.Version") + def field = clazz.getDeclaredField("ANDROID_GRADLE_PLUGIN_VERSION") + field.setAccessible(true) + version = field.get(null) + } catch (Exception ignore) { + } + } + return version + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0e4991cb..c7998d02 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,6 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=0.4.80 +VERSION_NAME=0.4.81 GROUP=com.meituan.robust