1

I need to use Newman, StackMob’s Http Client library in my Android project.

I use sbt-assembly to generate one single (uber)jar with all dependencies. The command gives me a very big jar file (48mb) and Android can't convert it to dex.

How can I add only needed dependencies to my jar library?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
iCaesar
  • 421
  • 2
  • 10
  • 23

1 Answers1

1

I wrote the entire section in sbt-assembly's README on excluding JARs and files.

When you say:

How can i add only needed dependencies to my jar library?

The word "dependencies" in context of sbt-assembly usually means dependent jars. The problem is at the jar level, you'd need all of them. What you have to do is find out *.class files that are not being used and exclude that out of the final fat jar. sbt-assembly does have merge strategy which you can use to ignore files.

For Android development however, because there are so many files to exclude, you'd need something that does the analysis automatically. That's where ProGuard comes in. This will make the resulting jar much smaller. But it is also a bit of a voodoo, since you might not be able to know if you need certain class or not for sure. Try pfn/android-sdk-plugin if you haven't yet. It caches ProGuard result and makes it much faster.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
  • thx for answer, i'll try it one more problem is that by using sbt assembly, it add to my fat jar all dependencies and one more scala library, i saw a lot of examples ow to exlude adding scala into jar but no one help me who can explain me how to do that – iCaesar Dec 19 '13 at 11:01
  • excluding scala lib from our fat jar gives bad results, so now i'am trying to configurate and use ProGuard – iCaesar Dec 19 '13 at 12:53