Skip to content

Commit

Permalink
Add proguard configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 committed Jan 9, 2022
1 parent 1f5968b commit ba07189
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
32 changes: 32 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jmailen.gradle.kotlinter.tasks.FormatTask
import org.jmailen.gradle.kotlinter.tasks.LintTask
import proguard.gradle.ProGuardTask

plugins {
kotlin("jvm") version "1.6.10"
Expand All @@ -18,6 +19,17 @@ plugins {
id("com.github.ben-manes.versions") version "0.39.0"
}

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

group = "ca.gosyer"
version = "1.2.1"

Expand Down Expand Up @@ -161,6 +173,26 @@ tasks {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
}
register<ProGuardTask>("optimizeUberJar") {
group = "compose desktop"
val packageUberJarForCurrentOS = getByName("packageUberJarForCurrentOS")
dependsOn(packageUberJarForCurrentOS)
val uberJars = packageUberJarForCurrentOS.outputs.files
injars(uberJars)
outjars(
uberJars.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")
}
}

fun isNonStable(version: String): Boolean {
Expand Down
66 changes: 66 additions & 0 deletions proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-dontobfuscate
-keepattributes Signature,LineNumberTable

-keep,allowoptimization class ca.gosyer.** { public protected *; }
-keep class ca.gosyer.ui.main.MainKt {
public static void main(java.lang.String[]);
}
-keep class 'module-info'

# Kotlin
# todo optimize more
-keep class kotlin.reflect.** { *; }

# Log4J
-dontwarn org.apache.logging.log4j.**
-keep class org.apache.logging.log4j.** { *; }

# SLF4J
-dontwarn org.apache.logging.slf4j.**
-keep class org.apache.logging.slf4j.** { *; }

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

# DarkLaf
# todo optimize more
-keep class com.github.weisj.darklaf.** { *; }
-dontwarn com.github.weisj.darklaf.**

# Ktor
-dontwarn io.ktor.network.sockets.DatagramSendChannel

# Coroutines
-keep class kotlinx.coroutines.swing.** { *; }
-dontwarn kotlinx.coroutines.**

# Other
-dontwarn org.pbjar.jxlayer.plaf.ext.TransformUI
-dontwarn com.kitfox.svg.app.ant.SVGToImageAntTask
-dontwarn nl.adaptivity.xmlutil.StAXWriter
-keep class com.sun.jna.** { *; }

# 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 ca.gosyer.** {
*** Companion;
}
-keepclasseswithmembers class ca.gosyer.** {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep Skia
-keep class org.jetbrains.skia.** { *; }
-keep class org.jetbrains.skiko.** { *; }

0 comments on commit ba07189

Please sign in to comment.