0

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.

Goofyahead
  • 5,874
  • 6
  • 29
  • 33
  • 1
    How exactly do you feed these classes into the other build? These are source files, not class files. – Peter Niederwieser Oct 30 '14 at 19:01
  • as a jar on libs and on the build.gradle compile files ('libs/myjar.jar') – Goofyahead Oct 30 '14 at 22:12
  • Ok so I discovered that I was creating a jar with the java files and I needed the compiled class adding this from fileTree(dir: 'build/intermediates/classes/release') made it, but where does it says this in the doc? or what doc should I relay on? any book? – Goofyahead Oct 30 '14 at 22:59

1 Answers1

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.

Sundeep Gupta
  • 1,887
  • 3
  • 24
  • 35
  • Error:(63, 0) Could not find property 'output' on source set main. What did work is from fileTree(dir: 'build/intermediates/classes/release') that just picks up the dest dir of compiled classes, but where is the description of all this sourcesets? what main stands for? and output? – Goofyahead Oct 31 '14 at 09:57