Giter Club home page Giter Club logo

Comments (4)

ellet0 avatar ellet0 commented on July 18, 2024 1

But since you added -dontwarn javax.swing.** -dontwarn java.awt.** the build was not failing; it's usually fine to ignore some warnings but they should give you an indication of classes that are missing and that should potentially be provided as libraryjars.

Agreed. which made it harder to debug and caused unexpected behavior.

It's a common issue since many tutorials and examples online use ignorewarnings or ignore the warnings from the JDK which is something I didn't quite understand

I appreciate your guidance on this.

from proguard.

ellet0 avatar ellet0 commented on July 18, 2024

Not directly related: it seems this line is needed even when using Shadow JAR:

       // This will include the Kotlin library jars, it will be needed even though Shadow JAR already includes it
        // to solve all warnings that are related to Kotlin without ignoring them
        injars(sourceSets.main.get().compileClasspath)

To solve all warnings coming from Kotlin library without using -dontwarn kotlin.** in proguard.pro

from proguard.

ellet0 avatar ellet0 commented on July 18, 2024

It seems this issue is from my side (incorrect configurations), I didn't include java.desktop.jmod from the JDK using libraryjars which is needed to avoid such issues, the final Proguard task will be:

tasks.register<proguard.gradle.ProGuardTask>("proguard") {
    dependsOn(tasks.shadowJar)
    configuration("proguard.pro")

    injars(tasks.shadowJar.flatMap { it.archiveFile })
    outjars(project.layout.buildDirectory.file("proguard-obfuscated.jar"))

    val javaHome = System.getProperty("java.home")
    // Automatically handle the Java version of this build.
    if (System.getProperty("java.version").startsWith("1.")) {
        // Before Java 9, the runtime classes were packaged in a single jar file.
        libraryjars("$javaHome/lib/rt.jar")
    } else {
        // As of Java 9, the runtime classes are packaged in modular jmod files.
        libraryjars(
            // filters must be specified first, as a map
            mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"),
            "$javaHome/jmods/java.base.jmod"
        )
        // Needed to support Java Swing/Desktop
        libraryjars(
            mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"),
            "$javaHome/jmods/java.desktop.jmod",
        )
    }

    allowaccessmodification()
    dontobfuscate()
    dontoptimize()
    verbose()

    // This will include the Kotlin library jars, Shadow JAR already includes it
    libraryjars(sourceSets.main.get().compileClasspath)

    printmapping(project.layout.buildDirectory.file("proguard-mapping.txt"))
}

And proguard.pro:

-verbose

-keepattributes *Annotation*

-keep class kotlin.Metadata { *; }

# Entry point to the app.
-keep class MainKt { *; }

This issue can still be useful for anyone who has similar issues as it solves other unrelated issues and can be useful to get started with Proguard on Kotlin/JVM in general.

from proguard.

mrjameshamilton avatar mrjameshamilton commented on July 18, 2024

Hi @ellet0 ! Glad you solved your issue!

In these kind of cases, you would normally see "Referenced class not found" warnings or similar which by default would fail the build.

But since you added -dontwarn javax.swing.** -dontwarn java.awt.** the build was not failing; it's usually fine to ignore some warnings but they should give you an indication of classes that are missing and that should potentially be provided as libraryjars.

from proguard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.