Skip to content

Commit

Permalink
feat: add proguard initial step into Flank configuration (#1078)
Browse files Browse the repository at this point in the history
* Added proguard with default setup

* Added proguard config options for succesful build

* Update test_runner/proguard/config.pro

Co-authored-by: Jan Góral <[email protected]>

* added minimization

Co-authored-by: Jan Góral <[email protected]>
  • Loading branch information
Sloox and jan-goral authored Sep 17, 2020
1 parent 1cae67f commit 88bd2de
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions test_runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Expand All @@ -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)
Expand Down
70 changes: 70 additions & 0 deletions test_runner/proguard/config.pro
Original file line number Diff line number Diff line change
@@ -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 <fields>;
}

# Proguard configuration for Jackson 2.x
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-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.** { *; }

0 comments on commit 88bd2de

Please sign in to comment.