使用带有gradle的proguard创建混淆的应用程序jar时出现重复的zip条目

时间:2019-03-15 14:32:46

标签: java gradle proguard obfuscation

Java应用程序本身不包含任何第三方库依赖项。而且,如果我删除了doc <- c( "closed door", "Open door", "door", "doo", "oor", "house" ) doc_corpus <- Corpus( VectorSource(doc) ) control_list <- list(removePunctuation = TRUE, tolower = TRUE) tdm <- DocumentTermMatrix(doc_corpus, control = character_tokenize(doc)) tf <- as.matrix(tdm) 任务和第obfuscate行,则标准jar将生成并可以运行。

错误..

jar.finalizedBy(project.tasks.obfuscate)

* What went wrong: Execution failed for task ':obfuscate'. > java.io.IOException: Can't write [/Users/rob/git/repo/build/libs/tool.out.jar] (Can't read [/Users/rob/git/repo/build/libs/tool.jar] (Duplicate zip entry [com/example/cli/j.class == tool.jar:com/example/cli/HelperUtils$5.class])) ..

build.gradle

task obfuscate(type: proguard.gradle.ProGuardTask) { configuration 'proguard.txt' injars "build/libs/tool.jar" outjars "build/libs/tool.out.jar" libraryjars "${System.getProperty('java.home')}/lib/rt.jar" } jar { archiveName = "tool.jar" from sourceSets.main.output.classesDir include '**/cli/*.class' manifest { attributes 'Main-Class': 'com.example.cli.Tool' } } jar.finalizedBy(project.tasks.obfuscate) ..

proguard.txt

该应用程序包含3个Java类文件..

-keep public class com.example.cli.* {*;}

1 个答案:

答案 0 :(得分:0)

jar任务中添加了以下内容:

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    ..
}