[英]Gradle doesn't build if sources jar is present
I'm using a jar in my Android Studio project, secretshare-1.4.1.jar
. 我在Android Studio项目secretshare-1.4.1.jar
使用了一个jar。 Now, I also want to be able to see the source code of this, so I added secretshare-1.4.1-sources.jar
to the libs forlder without adding it to the dependancies of the project. 现在,我还希望能够看到它的源代码,因此我将secretshare-1.4.1-sources.jar
添加到libs forlder中,而没有将其添加到项目的依赖关系中。 This allows me to browse the classes of the library along with their source. 这使我可以浏览库的类及其源代码。
But, the problem is that I can't build the project if I do that. 但是,问题是,如果这样做,我将无法构建项目。 The issue seems that the two jars have the same classes, so gradle gives a duplicate file error. 问题似乎是两个罐子具有相同的类,因此gradle给出了重复的文件错误。 But the sources jar isn't even present in the build.gradle
file. 但是source jar甚至没有出现在build.gradle
文件中。
Here is a sample code that I'm trying to run : 这是我要运行的示例代码:
import com.tiemens.secretshare.main.cli.MainSplit;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
...
public static void main(String[] args){
String s = "test message";
String k = "1";
String n = "2";
String[] splitArgs = {"-n", n, "-k", k, "-sS", s};
MainSplit.SplitInput splitInput = MainSplit.SplitInput.parse(splitArgs);
MainSplit.SplitOutput splitOutput = splitInput.output();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
splitOutput.print(ps);
String content = baos.toString(); // e.g. ISO-8859-1
System.out.println(content);
}
}
Here is the build.gradle: 这是build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.sakhuja.ayush.secretsafe"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
compile files('libs/secretshare-1.4.1.jar')
}
The error message that I get is: 我收到的错误消息是:
Error:Gradle: duplicate files during packaging of APK D:\z\Academics\Code\SecretSafe\app\build\outputs\apk\app-debug-unaligned.apk
Error:Gradle: Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK html/SecretShareApplet.html
File 1: D:\z\Academics\Code\SecretSafe\app\libs\secretshare-1.4.1.jar
File 2: D:\z\Academics\Code\SecretSafe\app\libs\secretshare-1.4.1.jar
And the error just goes away if I delete secretshare-1.4.1-sources.jar
from the libs folder. 如果我从libs文件夹中删除secretshare-1.4.1-sources.jar
,错误就会消失。 But I really want to keep it as I want to refer to the library's source code. 但是我真的想保留它,因为我想参考库的源代码。 Suggestions? 有什么建议吗?
Your 你的
compile fileTree(include: ['*.jar'], dir: 'libs')
is going to grab every jar in the libs dir, including the secretshare-1.4.1-sources.jar. 将获取libs目录中的每个jar,包括secretshare-1.4.1-sources.jar。 This also makes the 4 ending lines in your configuration block unnecessary. 这也使配置块中的4条结束线不再需要。 Exclude the secretshare-1.4.1-sources.jar specifically from the file tree: 从文件树中专门排除secretshare-1.4.1-sources.jar:
fileTree(include: ['*.jar'], dir: 'libs', excludes: ['secretshare-1.4.1-sources.jar'])
I'd also recommend removing the final 4 lines from the config block, but that's just a suggestion and not strictly the question. 我还建议从config块中删除最后4行,但这仅是一个建议,而不是严格的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.