用gradle创建jar,当导入类时无法在同一个包中看到其他类 [英] created jar with gradle, when imported a class cannot see the others in same package
问题描述
我一直在尝试使用gradle来创建一个我的库模块(我正在构建的SDK)这个任务。
I've been trying to use gradle to create a jar of my library module (an SDK that I'm building) with this task.
task sourcesJar(type: Jar) {
archiveName='here.jar'
from android.sourceSets.main.java.sourceFiles
}
创建jar后,这个项目有4个类,所有类都在jar中,扩展名为.java。
And the jar is created, this project has 4 classes, all of them are in the jar with a .java extension.
jar tvf的输出
output of jar tvf
0 Thu Oct 30 19:37:00 CET 2014 META-INF/
25 Thu Oct 30 19:37:00 CET 2014 META-INF/MANIFEST.MF
0 Wed Oct 15 18:31:24 CEST 2014 com/
0 Thu Oct 30 16:57:36 CET 2014 com/bastly/
0 Thu Oct 30 18:57:38 CET 2014 com/bastly/SDK/
357 Thu Oct 30 16:57:30 CET 2014 com/bastly/SDK/BasicWrapper.java
430 Thu Oct 30 16:57:30 CET 2014 com/bastly/SDK/MessagePayload.java
284 Thu Oct 30 16:57:30 CET 2014 com/bastly/SDK/MobaseMessage.java
4997 Thu Oct 30 18:57:38 CET 2014 com/bastly/SDK/RTmobase.java
267 Thu Oct 30 16:57:22 CET 2014 com/bastly/SDK/RTmobaseCallbacks.java
365 Thu Oct 30 16:57:30 CET 2014 com/bastly/SDK/UserWrapper.java
当我在另一个项目中添加这个jar并添加到gradle构建它时出现,我可以看到所有的java类,但RTmobase的主类使用RTmovaseCallback类,似乎无法找到它并且android studio说:
When I add this jar in another project and add to gradle build it appears and I can see all the java classes, but the main class that is RTmobase uses RTmovaseCallback class and it seems that it can't be found and android studio says:
无法解析符号'RTmovaseCallback'
cannot resolve symbol 'RTmovaseCallback'
public class RTmobase <T,S> {
private Socket socket = null;
private String apiKey;
private String userName;
private RTmobaseCallbacks cb;
...
这与jar任务有关吗?应该包含在MANIFEST.MF中的类路径?我不知道我错过了什么,但我有点卡住了。
Is this related with the jar task? with the class path that should be included in the MANIFEST.MF? I don't know what I'm missing but I'm kind of stuck.
任何帮助都将不胜感激。
谢谢。
Any help would be appreciated. Thanks.
推荐答案
使用此功能(请参阅更改>)
Use this (See change in from
)
task sourcesJar(type: Jar) {
archiveName='here.jar'
from android.sourceSets.main.output
}
这应该创建带有类的jar。请参阅 Gradle用户指南中的第27.7.3节,例如
Gradle用户指南是一个很好的资源来源。
This should create the jar with classes. Refer section 27.7.3 in Gradle User Guide for example Gradle User Guide is good source to start with.
这篇关于用gradle创建jar,当导入类时无法在同一个包中看到其他类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!