[Android Pro] Androidstudio Exporting Jar Packages

Source: Internet
Author: User

reference:http://blog.csdn.net/beijingshi1/article/details/38681281

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:

Buildscript {repositories {mavencentral ()} dependencies {Classpat          h ' com.android.tools.build:gradle:0.12.+ '}} Apply plugin: ' Com.andriod.library ' Android {                  Compilesdkversion buildtoolsversion = "Sourcesets" {defaultconfig { Testpackagename ' com.android.volley.tests '} main {asset S.srcdirs = [' assets '] res.srcdirs = [' res '] aidl.srcdirs = [' src '] resources.srcdirs = [' src '] renderscript.srcdirs = [' src '] java.s Rcdirs = [' src '] manifest.srcfile ' androidmanifest.xml '} i Nstrumenttest.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, and 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 ()} dependencies {Clas spath ' com.android.tools.build:gradle:0.12.+ '}}//define a function, target is the name of the file that generated the jar package, and Classdir is the text of the class file Piece clip def makejar (String target,string classdir) {exec{executable "jar"//Call Jar AR                      GS "CVF", Target args "-C", Classdir 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 buildtoolsversion = "20"                          Sourcesets {defaultconfig {testpackagename ' com.android.volley.tests '} Main {assets.Srcdirs = [' assets '] res.srcdirs = [' res '] aidl.srcdirs = [' src '] Resources.srcdirs = [' src '] renderscript.srcdirs = [' src '] java.src                          Dirs = [' 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. Specific more details, you can go to the official website to find the answer, or leave a message to ask me can also.

[Android Pro] Androidstudio Exporting Jar Packages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.