Closed LazyIonEs closed 4 months ago
While I was solving the problem on my own I found this : #1675 I tried Execute packageUberJarForCurrentOS, Run with java -jar file.jar, and an error occurred. According to the operation in the article, I added
tasks.register<Zip>("repackageUberJar") {
val packageReleaseUberJarForCurrentOS = tasks.getByName("packageReleaseUberJarForCurrentOS")
dependsOn(packageReleaseUberJarForCurrentOS)
val file = packageReleaseUberJarForCurrentOS.outputs.files.first()
val output = File(file.parentFile, "${file.nameWithoutExtension}-repacked.jar")
archiveFileName.set(output.absolutePath)
destinationDirectory.set(file.parentFile.absoluteFile)
exclude("META-INF/*.SF")
exclude("META-INF/*.RSA")
exclude("META-INF/*.DSA")
from(project.zipTree(file))
doLast {
delete(file)
output.renameTo(file)
logger.lifecycle("The repackaged jar is written to ${archiveFile.get().asFile.canonicalPath}")
}
}
I Execute packageUberJarForCurrentOS again, and Run with java -jar file.jar, all functions run normally, but when I want to Execute packageReleaseDistributionForCurrentOS, I found that there will still be SecurityException, so How to exclude few META-INF files for packageReleaseDistributionForCurrentOS, I think this may work for me very useful
I tried again to solve this problem myself
runReleaseDistributable
and an error occurs.
jarsigner -verify
, and it will prompt that the jar has been verified.jarsigner -verify
again, prompt
jarsigner: java.lang.SecurityException: SHA-256 digest error for org/bouncycastle/LICENSE.class
META-INF/*.RSA, META-INF/*.SF, META-INF/*.DSA, META-INF/*.EC
files from the copied bcpkix, bcprov, and bcutil jars.zip -d file.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*.DSA' 'META-INF/*.EC'
I want to know what was filtered in step 2, and how can I delete some files under META-INF when copying?
I'm very sorry. During my subsequent debugging, I found that this has nothing to do with resources
. I will provide a minimal reproduction program to help troubleshoot the problem.
https://github.com/LazyIonEs/compose-multiplatform-desktop-template
In the above program, when I add in compose-desktop.pro
-keepclasseswithmembers public class MainKt {
public static void main(java.lang.String[]);
}
-keep class org.bouncycastle.** { *; }
When executing runReleaseDistributable
, an error message java.lang.SecurityException: SHA-256 digest error for org/bouncycastle/operator/OperatorCreationException.class
will appear.
I think it may be because of the rule -keep class org.bouncycastle.** { *; }
, but when I delete it, the rule in compose-desktop.pro
is
-keepclasseswithmembers public class MainKt {
public static void main(java.lang.String[]);
}
# -keep class org.bouncycastle.** { *; }
I executed runReleaseDistributable
again, and an error message cannot create signer: no such algorithm: SHA256WITHRSA for provider BC
appeared.
I don't understand why
Can you help me solve this problem?
The following code in the AbstractProguardTask
file
jarsConfigurationFile.ioFile.bufferedWriter().use { writer ->
val toSingleOutputJar = joinOutputJars.orNull == true
for ((input, output) in inputToOutputJars.entries) {
writer.writeLn("-injars '${input.normalizedPath()}'")
if (!toSingleOutputJar)
writer.writeLn("-outjars '${output.normalizedPath()}'")
}
if (toSingleOutputJar)
writer.writeLn("-outjars '${mainJarInDestinationDir.ioFile.normalizedPath()}'")
for (jmod in jmods) {
writer.writeLn("-libraryjars '${jmod.normalizedPath()}'(!**.jar;!module-info.class)")
}
}
Does adding (!META-INF/*.SF,!META-INF/*.RSA,!META-INF/*.DSA)
after -injars
solve this problem?
writer.writeLn("-outjars '${output.normalizedPath()}' (!META-INF/*.SF,!META-INF/*.RSA,!META-INF/*.DSA)")
All of the above is caused by the introduction of signed jar I'm not sure if this is correct, but I'm still trying to figure it out.
Solution Found
@LazyIonEs What the solution?
@LazyIonEs What the solution?
I exclude the package introduced in the dependency by exclude(group = "org.bouncycastle", module = "bcpkix-jdk18on")
, and introduce implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
I delete the signature file in the jar package in advance by executing the command zip -d file.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*.DSA' 'META-INF/*.EC'
I don't know if there are other solutions, but this method works for me
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Describe the bug I turned on obfuscation in the project, and when I used stringResource(Res.string.app_name), there was a crash. I'm not sure what's causing it, but when I turn off obfuscation, everything works fine again, but for some reason, I still prefer to turn on obfuscation. I don't know if it's because my obfuscation is not configured correctly. I can't solve it. Please help me with this problem
Affected platforms
Versions
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen. normal operation
Screenshots
Additional context
compose-desktop.pro