Skip to content

Commit 7ac53ee

Browse files
committed
add proguard optimization
1 parent 9cc5153 commit 7ac53ee

File tree

16 files changed

+583
-353
lines changed

16 files changed

+583
-353
lines changed

build.gradle.kts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
kotlin("plugin.power-assert")
1212
// kotlin("plugin.parcelize")
1313
id("dev.reformator.stacktracedecoroutinator")
14-
id("org.bytedeco.gradle-javacpp-platform") version "1.5.10"
14+
// id("org.bytedeco.gradle-javacpp-platform") version "1.5.10"
1515
}
1616

1717
//val appVersionCode = 1
@@ -24,6 +24,14 @@ repositories {
2424
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
2525
google()
2626
}
27+
28+
java {
29+
toolchain {
30+
vendor = JvmVendorSpec.ADOPTIUM
31+
languageVersion = JavaLanguageVersion.of(21)
32+
}
33+
}
34+
2735
kotlin {
2836
jvm("desktop")
2937
sourceSets {
@@ -34,7 +42,7 @@ kotlin {
3442
implementation(compose.foundation)
3543
implementation(compose.material)
3644
implementation(compose.material3)
37-
//// implementation(compose.material3AdaptiveNavigationSuite)
45+
implementation(compose.material3AdaptiveNavigationSuite)
3846
implementation(compose.materialIconsExtended)
3947
// implementation(compose.material3AdaptiveNavigationSuite)
4048

@@ -54,19 +62,23 @@ kotlin {
5462
}
5563

5664
desktopMain.dependencies {
57-
implementation(compose.desktop.currentOs)
65+
implementation(compose.desktop.currentOs){
66+
exclude("org.jetbrains.compose.material")
67+
}
5868

5969
implementation(Kotlin.stdlib)
6070
implementation(Kotlin.stdlib.common)
6171

6272
implementation(KotlinX.coroutines.core)
73+
// explicit include to fix proguard warning
74+
implementation(KotlinX.serialization.core)
6375
implementation(KotlinX.serialization.json)
6476
implementation(KotlinX.datetime)
6577

6678
implementation(Ktor.client.core)
6779
implementation(Ktor.client.json)
6880
implementation(Ktor.client.cio)
69-
implementation("io.ktor:ktor-network:_")
81+
// implementation("io.ktor:ktor-network:_")
7082

7183
// implementation("org.deepsymmetry:lib-carabiner:_")
7284

@@ -75,20 +87,18 @@ kotlin {
7587

7688
// implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:_")
7789

78-
// MIDI xperiments.. WIP
79-
implementation("dev.atsushieno:ktmidi:_")
80-
implementation("dev.atsushieno:ktmidi-jvm-desktop:_")
81-
api("dev.atsushieno:libremidi-javacpp:_")
82-
api("dev.atsushieno:libremidi-javacpp-platform:_")
90+
// MIDI experiments.. WIP
91+
// implementation("dev.atsushieno:ktmidi:_")
92+
// implementation("dev.atsushieno:ktmidi-jvm-desktop:_")
93+
// api("dev.atsushieno:libremidi-javacpp:_")
94+
// api("dev.atsushieno:libremidi-javacpp-platform:_")
8395

8496
implementation("io.github.pdvrieze.xmlutil:serialization:_")
8597
// implementation("com.ryanharter.kotlinx.serialization:kotlinx-serialization-xml:_")
8698
implementation("io.github.xn32:json5k:_")
8799

88100
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:_")
89101

90-
implementation("io.obs-websocket.community:client:_")
91-
92102
implementation("io.github.cdimascio:dotenv-kotlin:_")
93103

94104
implementation("io.github.oshai:kotlin-logging:_")
@@ -98,12 +108,16 @@ kotlin {
98108

99109
implementation("io.github.kdroidfilter:platformtools.core:_")
100110
implementation("io.github.kdroidfilter:platformtools.appmanager:_")
101-
implementation("io.github.kdroidfilter:platformtools.releasefetcher:_")
111+
implementation("io.github.kdroidfilter:platformtools.releasefetcher:_") {
112+
exclude("org.slf4j", "slf4j-simple")
113+
}
102114
implementation("io.github.kdroidfilter:platformtools.darkmodedetector:_")
103115
implementation("io.github.kdroidfilter:platformtools.permissionhandler:_")
104116

105117
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:_")
106-
implementation("dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm-legacy:_")
118+
implementation("io.projectreactor.tools:blockhound:_")
119+
120+
// implementation("dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm-legacy:_")
107121

108122
// Include the Test API
109123
// testImplementation(compose.desktop.uiTestJUnit4)
@@ -166,10 +180,14 @@ compose.desktop {
166180
application {
167181
buildTypes.release {
168182
proguard {
169-
isEnabled = false
170-
version = "7.4.0" // may break with compose-navigation
183+
// isEnabled = false
184+
version = "7.7.0"
171185
// optimize = false
172186
// obfuscate = false
187+
188+
configurationFiles.from(
189+
project.file("compose-desktop.pro")
190+
)
173191
}
174192
}
175193
mainClass = "Main"
@@ -179,7 +197,9 @@ compose.desktop {
179197
)
180198
jvmArgs += listOf(
181199
"-Xmx1G",
182-
"--add-opens", "java.base/java.lang=ALL-UNNAMED"
200+
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
201+
// required by blockhound
202+
"-XX:+AllowRedefinitionToAddDeleteMethods",
183203
)
184204

185205
// nativeDistributions {
@@ -208,7 +228,7 @@ compose.desktop {
208228
// TargetFormat.Exe,
209229
// TargetFormat.Deb,
210230
)
211-
packageName = "moe.nikky.nestctrl"
231+
packageName = "nestctrl"
212232
packageVersion = appVersion
213233
vendor = "nikkyai"
214234
// this.vendor = null
@@ -249,7 +269,7 @@ project.afterEvaluate {
249269
val runDistributable by getting(AbstractRunDistributableTask::class) {
250270
// appImageRootDir.
251271
}
252-
val packageJar by creating {
272+
val packageJar by registering {
253273
group = "package"
254274
dependsOn(getByName("packageUberJarForCurrentOS"))
255275
doLast {
@@ -267,8 +287,9 @@ project.afterEvaluate {
267287
}
268288
}
269289
}
270-
val packageDistributable by creating(Zip::class) {
290+
val packageDistributable by registering(Zip::class) {
271291
group = "package"
292+
// from(createDistributable)
272293
from(createReleaseDistributable)
273294
from(project.file("README.md"))
274295
archiveBaseName.set("nestctrl")
@@ -288,7 +309,7 @@ project.afterEvaluate {
288309
// }
289310
// }
290311
}
291-
val deployDistributable by creating(Copy::class) {
312+
val deployDistributable by registering(Copy::class) {
292313
group = "package"
293314
doFirst {
294315
File(System.getProperty("user.home")).resolve("VJ").resolve("nestctrl").deleteRecursively()

compose-desktop.pro

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# from: https://github.com/Anamorphosee/stacktrace-decoroutinator#using-proguard
2+
-keep @kotlin.coroutines.jvm.internal.DebugMetadata class * { *; }
3+
-keep @dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorTransformed class * { *; }
4+
5+
6+
7+
# from: https://github.com/java-native-access/jna/issues/1187#issuecomment-626251894
8+
-keep class com.sun.jna.** { *; }
9+
-keep class * implements com.sun.jna.** { *; }
10+
11+
12+
13+
# from: https://github.com/JetBrains/compose-multiplatform/issues/4883#issuecomment-2156012785
14+
-keep class androidx.compose.runtime.** { *; }
15+
-keep class androidx.collection.** { *; }
16+
-keep class androidx.lifecycle.** { *; }
17+
-keep class androidx.compose.ui.text.platform.ReflectionUtil { *; }
18+
19+
# We're excluding Material 2 from the project as we're using Material 3
20+
-dontwarn androidx.compose.material.**
21+
22+
# Kotlinx coroutines rules seems to be outdated with the latest version of Kotlin and Proguard
23+
-keep class kotlinx.coroutines.** { *; }
24+
25+
26+
27+
# from: https://github.com/Kotlin/kotlinx.serialization/issues/2719#issuecomment-2189193638
28+
-keepclassmembers public class **$$serializer {
29+
private ** descriptor;
30+
}
31+
32+
# attempting to fix json5k
33+
-keep class io.github.xn32.json5k.** { *; }
34+
35+
# -keepattributes *Annotation*
36+
37+
# -keepclassmembers public class **$$serializer$annotationImpl$** {
38+
# private ** value;
39+
# private ** namespace;
40+
# private ** prefix;
41+
# }
42+
#
43+
#
44+
# -keep @nl.adaptivity.xmlutil.serialization.XmlSerialName public class *
45+
46+
## remove some stupid warnings for things we do not use
47+
-dontwarn jakarta.**
48+
-dontwarn org.tukaani.xz.**
49+
-dontwarn lombok.**
50+
-dontwarn edu.umd.cs.findbugs.**
51+
-dontwarn org.junit.**
52+
-dontwarn org.codehaus.commons.**
53+
-dontwarn org.codehaus.janino.**
54+
-dontwarn com.oracle.svm.**
55+
-dontwarn javax.servlet.**
56+
-dontwarn org.eclipse.jetty.**
57+
-dontwarn ch.qos.cal10n.**
58+
-dontwarn javassist.**
59+
60+
# -dontwarn reactor.blockhound.**
61+
-dontwarn javassist.**
62+
63+
# logging
64+
65+
-keep public class org.slf4j.** { *; }
66+
-keep public class ch.** { *; }
67+
68+
# blockhound
69+
-dontnote reactor.blockhound
70+
-dontwarn reactor.blockhound
71+
# -keep class reactor.blockhound.** { *; }
72+
-dontwarn reactor.core.scheduler.NonBlocking
73+
-dontwarn io.reactivex.internal.schedulers.NonBlockingThread
74+
-dontwarn **.AutoService
75+
-dontwarn javax.annotation.**
76+
77+
-printmapping mapping.txt
78+
# -dontoptimize
79+
80+
81+
-ignorewarnings

settings.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ dependencyResolutionManagement {
3737
plugins {
3838
// See https://jmfayard.github.io/refreshVersions
3939
id("de.fayard.refreshVersions") version "0.60.5"
40+
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
41+
//// # available:"0.6.0"
42+
//// # available:"0.7.0"
43+
//// # available:"0.8.0"
44+
//// # available:"0.9.0"
45+
//// # available:"0.10.0"
4046
}

src/desktopMain/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable
1717
import nestdrop.deck.Deck
1818
import nestdrop.deck.applyConfig
1919
import nestdrop.deck.configFlow
20-
import obs.LOOM
20+
import utils.LOOM
2121
import tags.PresetPlaylist
2222
import ui.screens.customSearches
2323
import utils.prettyPrint

src/desktopMain/kotlin/Main.kt

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import androidx.compose.ui.window.WindowPosition
2727
import androidx.compose.ui.window.awaitApplication
2828
import androidx.compose.ui.window.rememberDialogState
2929
import androidx.compose.ui.window.rememberWindowState
30-
import dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime
3130
import io.github.kdroidfilter.platformtools.appmanager.WindowsInstallerConfig
3231
import io.github.kdroidfilter.platformtools.darkmodedetector.isSystemInDarkMode
3332
import io.github.oshai.kotlinlogging.KotlinLogging
3433
import kotlinx.coroutines.Dispatchers
3534
import kotlinx.coroutines.FlowPreview
35+
import kotlinx.coroutines.debug.CoroutinesBlockHoundIntegration
3636
import kotlinx.coroutines.delay
3737
import kotlinx.coroutines.flow.debounce
3838
import kotlinx.coroutines.flow.flowOn
@@ -53,9 +53,11 @@ import nestdrop.watchNestdropConfig
5353
import org.jetbrains.compose.resources.painterResource
5454
import osc.runNestDropSend
5555
import osc.startNestdropOSC
56+
import reactor.blockhound.BlockHound
5657
import tags.startTagsFileWatcher
5758
import ui.App
5859
import ui.components.verticalScroll
60+
import utils.className
5961
import java.text.SimpleDateFormat
6062
import java.util.*
6163
import kotlin.time.Duration.Companion.milliseconds
@@ -77,8 +79,19 @@ val decks = List(4) { index ->
7779
}
7880
}.filterNotNull()
7981

80-
object Main {
82+
val isObfuscated by lazy {
83+
try {
84+
Class.forName("tKredilSlacitreV".reversed()).also {
85+
logger.info { it }
86+
}
87+
false
88+
} catch (e: ClassNotFoundException) {
89+
logger.error(e) { "failed to load class" }
90+
true
91+
}
92+
}
8193

94+
object Main {
8295
@OptIn(FlowPreview::class)
8396
suspend fun initApplication(
8497
queues: Queues,
@@ -225,12 +238,28 @@ object Main {
225238
@JvmStatic
226239
fun main(args: Array<String>) {
227240
WindowsInstallerConfig.requireAdmin = false
228-
if (dotenv.get("DEBUG", "false").toBooleanStrictOrNull() == true) {
229-
// if(true) {
230-
val state = DecoroutinatorRuntime.load()
231-
logger.info { "enabling De-Corouti-nator: $state" }
241+
// blockhound.main()
242+
243+
println("Main: ${Main.toString()}")
244+
logger.info { Main.toString() }
245+
246+
247+
if(!isObfuscated) {
248+
logger.info { "not obfuscated" }
249+
logger.info { "installing blockhound" }
250+
BlockHound.install(CoroutinesBlockHoundIntegration())
251+
252+
// if (dotenv.get("DEBUG", "false").toBooleanStrictOrNull() == true) {
253+
//// if(true) {
254+
// val state = DecoroutinatorRuntime.load()
255+
// logger.info { "enabling De-Corouti-nator: $state" }
256+
// }
257+
} else {
258+
logger.info { "obfuscated: ${Main.className}" }
232259
}
233260

261+
262+
234263
// Activator.createParserTypes().forEach { (k,v) ->
235264
// logger.info { "parser $k: $v" }
236265
// }

0 commit comments

Comments
 (0)