From 88bd2ded15bd5e13860887829caaff1e33cfc795 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 17 Sep 2020 17:59:05 +0200 Subject: [PATCH] feat: add proguard initial step into Flank configuration (#1078) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added proguard with default setup * Added proguard config options for succesful build * Update test_runner/proguard/config.pro Co-authored-by: Jan Góral <60390247+jan-gogo@users.noreply.github.com> * added minimization Co-authored-by: Jan Góral <60390247+jan-gogo@users.noreply.github.com> --- buildSrc/src/main/kotlin/Deps.kt | 6 +++ test_runner/build.gradle.kts | 40 ++++++++++++++++++ test_runner/proguard/config.pro | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 test_runner/proguard/config.pro diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index ac61f20904..43c7a09353 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -1,4 +1,8 @@ object Versions { + + // https://github.com/Guardsquare/proguard + const val PROGUARD = "7.0.0" + // https://github.com/bugsnag/bugsnag-java/releases const val BUGSNAG = "3.6.1" @@ -126,6 +130,8 @@ object Libs { const val JANSI = "org.fusesource.jansi:jansi:${Versions.JANSI}" + const val PROGUARD = "com.guardsquare:proguard-gradle:${Versions.PROGUARD}" + //region Plugins const val DETEKT_FORMATTING = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.DETEKT}" //endregion diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index fefb7b898b..0db472d676 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -43,6 +43,7 @@ shadowJar.apply { exclude(dependency(Libs.TRUTH)) exclude(dependency(Libs.MOCKK)) exclude(dependency(Libs.JUNIT)) + exclude(dependency(Libs.PROGUARD)) exclude(dependency(Libs.DETEKT_FORMATTING)) } } @@ -251,6 +252,28 @@ dependencies { implementation(Libs.JANSI) } +// Fix Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.hash.Hashing.crc32c()Lcom/google/common/hash/HashFunction; +// https://stackoverflow.com/a/45286710 +configurations.all { + resolutionStrategy { + force("com.google.guava:guava:25.1-jre") + force(Libs.KOTLIN_REFLECT) + exclude(group = "com.google.guava", module = "guava-jdk5") + } +} + +buildscript { + repositories { + mavenLocal() + jcenter() + google() + } + dependencies { + classpath(Libs.PROGUARD) + } +} + + tasks.withType { kotlinOptions.jvmTarget = "1.8" } @@ -264,6 +287,23 @@ tasks.create("updateFlank", Exec::class.java) { commandLine = listOf("./bash/update_flank.sh") } +tasks.create("applyProguard", proguard.gradle.ProGuardTask::class.java) { + dependsOn("updateFlank") + description = "Apply proguard to flank and create a minimized jar" + dontwarn() + injars("./build/libs/flank.jar") + outjars("./build/libs/flank-proguard.jar") + libraryjars("${System.getProperty("java.home")}/lib/rt.jar") + libraryjars("./build/libs/flank-sources.jar") + configuration("./proguard/config.pro") + doLast { + copy { + from(file("$buildDir/libs/flank-proguard.jar")) + into(file("./bash/")) + } + } +} + // begin --- ASCII doc generation --- val generateCliAsciiDoc by tasks.registering(JavaExec::class) { dependsOn(tasks.classes) diff --git a/test_runner/proguard/config.pro b/test_runner/proguard/config.pro new file mode 100644 index 0000000000..28d8ae7896 --- /dev/null +++ b/test_runner/proguard/config.pro @@ -0,0 +1,70 @@ +-dontobfuscate +-allowaccessmodification +-keepattributes SourceFile, LineNumberTable +-dontwarn +-verbose +-dontoptimize +-dontnote kotlin.** +-dontnote kotlinx.** +-dontnote com.google.gson.** +-dontnote proguard.configuration.ConfigurationLogger + +-keep class ftl.Main { + public static void main(java.lang.String[]); +} + +#Kotlin +-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {} +-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {} +-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} +-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} + +-keep class kotlinx.coroutines.internal.MainDispatcherFactory {} +-keep class kotlinx.coroutines.CoroutineExceptionHandler {} +-keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {} +-keep class kotlinx.coroutines.android.AndroidDispatcherFactory {} + +# Most of volatile fields are updated with AFU and should not be mangled +-keepclassmembernames class kotlinx.** { + volatile ; +} + +# Proguard configuration for Jackson 2.x +-keep class com.fasterxml.jackson.databind.ObjectMapper { + public ; + protected ; +} +-keep class com.fasterxml.jackson.databind.ObjectWriter { + public ** writeValueAsString(**); +} +-keepnames class com.fasterxml.jackson.** { *; } +-keep class kotlin.Metadata { *; } +-keep class kotlin.reflect.** { *; } + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class com.bugsnag.android.NativeInterface { *; } +-keep class com.bugsnag.android.Breadcrumb { *; } +-keep class com.bugsnag.android.Breadcrumbs { *; } +-keep class com.bugsnag.android.Breadcrumbs$Breadcrumb { *; } +-keep class com.bugsnag.android.BreadcrumbType { *; } +-keep class com.bugsnag.android.Severity { *; } +-keep class com.bugsnag.android.ndk.BugsnagObserver { *; } +# Picocli +-keep class picocli.** { *; } +-keep interface picocli.** { *; } + +#ftl +-keep class ftl.** { *; } +-keep interface ftl.** { *; } + +#google auth +-keep class com.google.auth.** { *; } +-keep interface com.google.auth.** { *; } + +#ctc wstx +-keep class com.ctc.wstx.** { *; } +-keep interface com.ctc.wstx.** { *; }