Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Proguard shrinking and code optimization #317

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ plugins {
id("com.github.gmazzo.buildconfig") version "3.0.3" apply false
}

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.guardsquare:proguard-gradle:7.2.1") {
exclude("com.android.tools.build")
}
}
}

allprojects {
group = "suwayomi"

Expand Down Expand Up @@ -112,4 +123,5 @@ configure(projects) {
// dependency both in AndroidCompat and server, version locked by javalin
implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.4")
}
}
}

22 changes: 22 additions & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import de.undercouch.gradle.tasks.download.Download
import proguard.gradle.ProGuardTask
import java.time.Instant

plugins {
Expand Down Expand Up @@ -175,4 +176,25 @@ tasks {
)
}
}

register<ProGuardTask>("optimizeShadowJar") {
group = "shadow"
val shadowJar = getByName("shadowJar")
dependsOn(shadowJar)
val shadowJars = shadowJar.outputs.files.onEach { println(it.absolutePath) }
injars(shadowJars)
outjars(
shadowJars.map { file ->
File(file.parentFile, "min/" + file.name)
}
)
val javaHome = System.getProperty("java.home")
if (JavaVersion.current().isJava9Compatible) {
libraryjars("$javaHome/jmods")
} else {
libraryjars("$javaHome/lib/rt.jar")
//libraryjars("$javaHome/lib/jce.jar")
}
configuration("proguard-rules.pro")
}
}
138 changes: 138 additions & 0 deletions server/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
-dontobfuscate
-keepattributes Signature,LineNumberTable

-keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; }
-keep,allowoptimization class suwayomi.tachidesk.** { public protected *; }
-keep class suwayomi.tachidesk.manga.model.dataclass.* { *; }
-keep class suwayomi.tachidesk.MainKt {
public static void main(java.lang.String[]);
}
-keepdirectories suwayomi/tachidesk/**
-keepdirectories META-INF/**


# java.lang.ClassCastException: class javax.servlet.SessionTrackingMode not an enum
-keepclassmembers class * extends java.lang.Enum {
<fields>;
public static **[] values();
public static ** valueOf(java.lang.String);
}

# Jackston
#-keep class kotlin.Metadata { *; }
#-keep class kotlin.reflect.** { *; }


# Kotlin Serialization
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations

# kotlinx-serialization-json specific. Add this if you have java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer
-keepclassmembers class kotlinx.serialization.json.** {
*** Companion;
}
-keepclasseswithmembers class kotlinx.serialization.json.** {
kotlinx.serialization.KSerializer serializer(...);
}

-keep,includedescriptorclasses class eu.kanade.tachiyomi.**$$serializer { *; }
-keepclassmembers class eu.kanade.tachiyomi.** {
*** Companion;
}
-keepclasseswithmembers class eu.kanade.tachiyomi.** {
kotlinx.serialization.KSerializer serializer(...);
}

-keep,includedescriptorclasses class suwayomi.tachidesk.**$$serializer { *; }
-keepclassmembers class suwayomi.tachidesk.** {
*** Companion;
}
-keepclasseswithmembers class suwayomi.tachidesk.** {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep extension's common dependencies
-keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; }
-keep,allowoptimization class androidx.preference.** { *; }
-keep,allowoptimization class kotlin.** { public protected *; }
-keep,allowoptimization class kotlinx.coroutines.** { public protected *; }
-keep,allowoptimization class okhttp3.** { public protected *; }
-keep,allowoptimization class okio.** { public protected *; }
-keep,allowoptimization class rx.** { public protected *; }
-keep,allowoptimization class org.jsoup.** { public protected *; }
-keep,allowoptimization class com.google.gson.** { public protected *; }
-keep,allowoptimization class com.github.salomonbrys.kotson.** { public protected *; }
-keep,allowoptimization class com.squareup.duktape.** { public protected *; }
-keep,allowoptimization class app.cash.quickjs.** { public protected *; }
-keep,allowoptimization class uy.kohesive.injekt.** { public protected *; }
-keep,allowoptimization class kotlinx.serialization.** { public protected *; }

# Coroutines
-dontwarn kotlinx.coroutines.**

# OKHTTP
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.**

# Exposted
-keep class org.jetbrains.exposed.** { *; }
-keep class de.neonew.exposed.migrations.** { *; }

# H2
-keep class org.h2.Driver { *; }

# Javalin
-keep class org.eclipse.jetty.** { *; }
-dontwarn io.javalin.http.LeveledBrotliStream
-dontwarn io.javalin.plugin.metrics.**
-dontwarn io.javalin.plugin.rendering.**
-dontwarn com.nixxcode.jvmbrotli.common.BrotliLoader
-dontwarn com.nixxcode.jvmbrotli.enc.BrotliOutputStream

# Xml
-keep class org.apache.xerces.** { *; }
-dontwarn javax.xml.**
-dontwarn com.sun.xml.**
-dontwarn com.sun.org.apache.**
-dontwarn jdk.xml.internal.ErrorHandlerProxy
-dontwarn com.sun.beans.decoder.DocumentHandler
-dontwarn org.apache.xerces.**

# org.json
-dontwarn org.json.XMLTokener
-dontwarn org.json.JSONWriter

# Android
-dontwarn com.android.**
-dontwarn android.**
-dontwarn androidx.annotation.*

# Logback
-keep class ch.qos.logback.** { *; }
-dontwarn ch.qos.logback.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.slf4j.MDC
-dontwarn org.slf4j.MarkerFactory

# Dorkbox
-keep class dorkbox.systemTray.ui.** {
public <init>(...);
}
-keep class dorkbox.jna.** { *; }
-dontwarn dorkbox.**

# Java
-dontwarn javax.imageio.**
-dontwarn javax.swing.**
-dontwarn java.util.prefs.**

# Joda time
-dontwarn org.joda.convert.*

# Other
-keep class com.sun.jna.** { *; }
-dontwarn com.sun.rowset.**
-dontwarn com.reprezen.jsonoverlay.gen.**
-dontwarn org.h2.**
-dontwarn org.eclipse.jetty.**
-dontwarn org.antlr.runtime.tree.DOTTreeGenerator