created jar with gradle, when imported a class can

2019-09-07 06:02发布

问题:

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
}

And the jar is created, this project has 4 classes, all of them are in the jar with a .java extension.

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

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:

cannot resolve symbol 'RTmovaseCallback'

public class RTmobase <T,S> {

    private Socket socket = null;
    private String apiKey;
    private String userName;
    private RTmobaseCallbacks cb;
...

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.

回答1:

Use this (See change in from )

task sourcesJar(type: Jar) {
    archiveName='here.jar'
    from android.sourceSets.main.output
}

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.