I have the following dependencies in my build.gradle:
我的build.gradle中有以下依赖项:
dependencies {
compile 'com.google.guava:guava:18.0'
}
It works during compile time and the output jar is generated for my source code (which uses classes like com.google.common.collect.Maps from the guava libraries).
它在编译期间工作,并为我的源代码生成输出jar(它使用来自guava库的com.google.common.collect.Maps之类的类)。
I have a dex task which converts the output jar into a dex file:
我有一个dex任务,它将输出jar转换为dex文件:
task dex(dependsOn: jar, type:Exec) {
project.dexDir.mkdirs()
commandLine 'dx', '--dex', '--no-strict', '--output=' + buildDir +'/dex/' + project.name + '.jar', jar.archivePath
}
The problem is that the output jar doesn't have the guava dependencies, so when it's converted to dex, pushed to an android device and run there, I am getting java.lang.ClassNotFoundException: Didn't find class com.google.common.collect.Maps
问题是输出jar没有guava依赖项,所以当它转换为dex,推送到Android设备并在那里运行时,我得到java.lang.ClassNotFoundException:没找到com.google.common类.collect.Maps
Is there a way to get the guava dependencies to be included in the output jar for the javaCompile task that generates the output jar from my other source code? Thank you very much in advance!
有没有办法让guava依赖项包含在javaCompile任务的输出jar中,该任务从我的其他源代码生成输出jar?非常感谢你提前!
1 个解决方案
#1
This is usually called a "jar with dependencies" or sometimes, a "fat" jar. This solution is probably what you need:
这通常称为“具有依赖性的jar”或有时称为“胖”jar。这个解决方案可能就是您所需要的:
#1
This is usually called a "jar with dependencies" or sometimes, a "fat" jar. This solution is probably what you need:
这通常称为“具有依赖性的jar”或有时称为“胖”jar。这个解决方案可能就是您所需要的: