On Wed, Jan 15, 2014 at 3:45 PM, Traun Leyden <[email protected]>wrote:

> But still curious on whether it's possible to package an android library
> as a jar rather than an aar so that it's easier for Eclipse users to
> consume.
>

Definitely possible. We're using this, which is based on a post either here
on adt-dev or on StackOverflow:

android.libraryVariants.all { variant ->
  def name = variant.buildType.name
  if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
    return; // Skip debug builds.
  }
  def taskJarWithDependencies = project.tasks.create
"jarWithDependencies${name.capitalize()}", Jar
  taskJarWithDependencies.dependsOn variant.javaCompile
  taskJarWithDependencies.from {
    variant.javaCompile.destinationDir
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  }
  taskJarWithDependencies.appendix "-with-dependencies"
  artifacts.add('archives', taskJarWithDependencies);

  def taskJar = project.tasks.create "jar${name.capitalize()}", Jar
  taskJar.dependsOn variant.javaCompile
  taskJar.from variant.javaCompile.destinationDir
  artifacts.add('archives', taskJar)
}


There's some extra logic in there to handle including dependencies, since
jar consumers may not be able to read a POM to get dependencies (and those
dependencies might be AARs), but it is essentially what you need.

Of course, you'll have to be careful to not attempt to access any resources
from your jar, but it will work.

*Avram Lyon*
Android wrangler | Scopely, Inc.

Refer The Smartest Person You Know And Pocket $5,000!
* Learn more: scopely.com/referrals
<http://www.scopely.com/referrals/?page=4>*

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to