Unlike in eclipse, you can export a jar package directly. Androidstudio can only generate AAR packages.
seeing many friends on the internet asking how to export jar packages like eclipse, we just need to know the principle of it is possible.
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 a project project of Android-library, I modified his gradle version, changed to 0.12+,
Because I am the newest gradle2.0. Now its build.gradle file is as follows:
buildscript {repositories {mavencentral ()} dependencies {Classpat H ' com.android.tools.build:gradle:0.12.+ '}}apply plugin: ' Com.andriod.library ' Android {compilesdkversion bui Ldtoolsversion = "Sourcesets" {defaultconfig {testpackagename ' com.android.volley.tests ' } main {assets.srcdirs = [' assets '] res.srcdirs = [' res '] aidl.src Dirs = [' 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'll see a build folder under the Volley directory, under Build/intermediates/classes/release, we can see the class file generated by the Java file, and we just use the jar to package this folder.
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:
Buildscript { repositories { mavencentral () } Dependenci Es { classpath ' com.android.tools.build:gradle:0.12.+ ' }}//define a function, Target is the file name that generated the jar package, Classdir is the folder where the class file is located def makejar (String target,string classdir) { exec{ & nbsp executable "jar"//Call jar args "CVF",target args "-C", class dir args "", "." }}//Create a new task named Buildlib, dependent on build (build is a self-brought task) task Buildlib (dependson:[' build ') << { Makejar ("Volley.jar", "build/intermediates/classes/release")}apply plugin: ' Android-library ' Android { Compilesdkversion 19 buildtoolsversion = "$" sourcesets { DEF Aultconfig { testpackagename ' com.android.volley.tests ' &NBS P } &nbsP Main { assets.srcdirs = [' Assets ']   ; res.srcdirs = [' res '] &NBS P Aidl.srcdirs = [' src '] Resources.srcdirs &NBSP = [' src '] renderscript.srcdirs = [' src '] &NBSP ; Java.srcdirs = [' src '] Manifest.srcfile ' androidmanif Est.xml ' } instrumenttest.setroot (' tests ') &NBS P InstrumentTest.java.srcDirs = [' Tests/src '] }}
Now we're going to run the Buildlib task under the Volley folder.
Gradlew Buildlib
*_* has succeeded. Specific more details, you can go to the official website to find the answer, or leave a message to ask me can also.