Original link: http://blog.csdn.net/hjq842382134/article/details/38538097#
Unlike in eclipse, you can export a jar package directly. Androidstudio can only generate AAR packages.
See many friends on the Internet how can export jar package like eclipse, in fact, we just need to know the principle of it.
You can use the JAR command to package the resources you need and specify the jar package name.
Download the volley source code on the web and export the jar package as an example.
In the volley project, I changed his gradle version to 0.12+,
Because I am the newest gradle2.0. Now its build.gradle file is as follows:
[Java]View Plaincopy
- Buildscript {
- repositories {
- Mavencentral ()
- }
- dependencies {
- Classpath ' com.android.tools.build:gradle:0.12.+ '
- }
- }
- Apply plugin: ' com.andriod.library '
- Android {
- Compilesdkversion
- Buildtoolsversion = " a"
- sourcesets {
- Defaultconfig {
- Testpackagename ' com.android.volley.tests '
- }
- Main {
- Assets.srcdirs = [' Assets ']
- Res.srcdirs = [' res ']
- Aidl.srcdirs = [' src ']
- Resources.srcdirs = [' src ']
- Renderscript.srcdirs = [' src ']
- Java.srcdirs = [' src ']
- Manifest.srcfile ' Androidmanifest.xml '
- }
- Instrumenttest.setroot (' tests ')
- InstrumentTest.java.srcDirs = [' tests/src ']
- }
- }
Since the introduction of the volley project, I chose the recommended Gradle Wrapper, its role is to enable us in the Unix,windows platform
Compatible with the implementation. I'm using windows, so I'll get to the root of volley, volley I download to e:\
CD E:\Volley
Then enter the command:
Gradlew Clean Build
You will see a build folder under the Volley directory, under Build/intermediates/classes/release, we can see the Java file generated class file, we just need to package this folder with Jar.
Enter the following command, and remember that the last one is '. ', preceded by a space.
Jar CVF volley.jar-c build/intermediates/classes/release.
If you don't know what you mean, go
Http://blog.sina.com.cn/s/blog_93d133c601013hdm.html look down.
If there is no accident, you will see Volley.jar under the Volley folder.
But this is not what we want ah, I want to androidstudio automatically help me do well, build jar package.
This requires that we set up the Build.gradle in the
Gradle official website can know, task and project is gradle most important thing, my original idea is that,
Create a task, call the jar command to help me build the jar package, the result is successful, as follows:
[Java]View Plaincopy
- Buildscript {
- repositories {
- Mavencentral ()
- }
- dependencies {
- Classpath ' com.android.tools.build:gradle:0.12.+ '
- }
- }
- Define a function, target is the file name to generate the jar package, Classdir is the folder where the class file resides
- def makejar (String target,string classdir) {
- exec{
- Executable "jar" //Call jar
- Args "CVF", Target
- Args "-C", Classdir
- Args "","."
- }
- }
- Create a new task named Buildlib, dependent build (build is a self-brought task)
- Task Buildlib (dependson:[' build ') << {
- Makejar ("Volley.jar","Build/intermediates/classes/release")
- }
- Apply plugin: ' android-library '
- Android {
- Compilesdkversion
- Buildtoolsversion = " a"
- sourcesets {
- Defaultconfig {
- Testpackagename ' com.android.volley.tests '
- }
- Main {
- Assets.srcdirs = [' Assets ']
- Res.srcdirs = [' res ']
- Aidl.srcdirs = [' src ']
- Resources.srcdirs = [' src ']
- Renderscript.srcdirs = [' src ']
- Java.srcdirs = [' src ']
- Manifest.srcfile ' Androidmanifest.xml '
- }
- Instrumenttest.setroot (' tests ')
- InstrumentTest.java.srcDirs = [' tests/src ']
- }
- }
Now we're going to run the Buildlib task under the Volley folder.
Gradlew Buildlib
*_* has succeeded. More details, you can go to the official website to find the answer.
Go Androidstudio Exporting Jar Packages