Reputation: 25
I've just created an android library module, and now I'd like to export it as a .jar file (Like I used to do in Eclipse), so I can use it in others project just link it as an external library file.
The problem is that I've just read from the official site that "You cannot export a library module to a JAR file": https://developer.android.com/tools/projects/index.html
So how can I do that? Is there something similare that I can do to obtain the same result?
Thanks
Upvotes: 0
Views: 1551
Reputation: 126563
You must export it as .AAR
file. It is not possible to export an Android Studio library as a .jar
file.
Check this out: https://androidbycode.wordpress.com/2015/02/23/building-an-aar-library-in-android-studio/
Purpose of AAR: Library reuse has long been available in Java based applications through Java Archive (.jar) files. Android AAR files build upon this concept to allow you to package not only the source code but also the libraries self contained Android resources. The library can have its own manifest and resources and can also optionally provide assets, NDK built libraries, proguard configuration and even its own custom lint filters. This is all bundled into a zip archive that can be published to a repository for your team (or the world!) to get easy access from a Gradle build.
This is how to create the .AAR file by @alex18aa:
File
-> New module
-> Import aar/jar
, and then add the dependencie in the module settings, and linking it.
Upvotes: 1
Reputation: 7051
AAR: Look up AAR files etc. The way I do it is:
uploadArchives {
repositories.mavenDeployer {
repository(url: "someDirectory/")
}
}
Then ./gradlew clean build uploadArchives
JAR: If you don't have a resource file, just add this to your build.gradle:
task makeJarRelease(type: Copy) {
from("build/intermediates/bundles/release/")
into("some_directory/")
include("classes.jar")
rename("classes.jar", "yourlibname.jar")
}
Then run a ./gradlew clean build makeJarRelease
And that will do it.
Yeah, Android Studio exports .AAR files and that is the new standard. However, if you need a jarfile, thats how you can do it.
Again, you cannot have a res folder (meaning no XML files or drawables) if you want to do it this way.
Upvotes: 0
Reputation: 11038
Look into AAR files. They are Android libraries that can contain not only code, but also resources!
Upvotes: 0