0

What I want

I want to generate a jar out of my library project(this project uses gson in gradle)

What I'm doing

I've created a library module which uses Gson library. Gson library is added in build.gradle of the library module. I'm generating .aar file using gradle build command.Then I extracted the aar archive and copied classes.jar file to a new project's libs folder. When I try to call a method of library class which used Gson, it gives a runtime error, ClassNotFoundException.

Looks like the Gson class is not bundled with the jar. I'm not sure how to fix this. I've also tried to use gson jar in the library module instead of adding gradle dependency. I don't want to publish library to maven repository, I just want the jar file.

Community
  • 1
  • 1
Jainendra
  • 24,713
  • 30
  • 122
  • 169
  • 1
    no need to extract arr, just use the arr instead of jar. arr now contains everything you need. – David Jun 10 '16 at 06:42
  • @David Can't I do the same using jar? – Jainendra Jun 10 '16 at 06:44
  • A .jar is meant to be used via the gradle / maven dependency mechanism. If you don't want to add it to a maven repository (you could even have a local one on your pc) you would add the library project as gradle module dependency: http://stackoverflow.com/a/17490233/995891 – zapl Jun 10 '16 at 06:45
  • From Android library project, it is not possible to create jar file using android studio: check this: http://stackoverflow.com/a/17132055/4628611 – Mehta Jun 10 '16 at 06:46

1 Answers1

0

To solve this problem you can add gradle dependency on GSON in your main module of project which is using this library.

To be more clear :

Say, you built library "L" using GSON. Now you created project "X" which is using L Library.

So you just need to add gradle dependency on GSON in main module of project X.
Arpit Ratan
  • 2,976
  • 1
  • 12
  • 20