Go Androidstudio Exporting Jar Packages

Source: Internet
Author: User

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
  1. Buildscript {
  2. repositories {
  3. Mavencentral ()
  4. }
  5. dependencies {
  6. Classpath ' com.android.tools.build:gradle:0.12.+ '
  7. }
  8. }
  9. Apply plugin: ' com.andriod.library '
  10. Android {
  11. Compilesdkversion
  12. Buildtoolsversion = " a"
  13. sourcesets {
  14. Defaultconfig {
  15. Testpackagename ' com.android.volley.tests '
  16. }
  17. Main {
  18. Assets.srcdirs = [' Assets ']
  19. Res.srcdirs = [' res ']
  20. Aidl.srcdirs = [' src ']
  21. Resources.srcdirs = [' src ']
  22. Renderscript.srcdirs = [' src ']
  23. Java.srcdirs = [' src ']
  24. Manifest.srcfile ' Androidmanifest.xml '
  25. }
  26. Instrumenttest.setroot (' tests ')
  27. InstrumentTest.java.srcDirs = [' tests/src ']
  28. }
  29. }

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
  1. Buildscript {
  2. repositories {
  3. Mavencentral ()
  4. }
  5. dependencies {
  6. Classpath ' com.android.tools.build:gradle:0.12.+ '
  7. }
  8. }
  9. Define a function, target is the file name to generate the jar package, Classdir is the folder where the class file resides
  10. def makejar (String target,string classdir) {
  11. exec{
  12. Executable "jar" //Call jar
  13. Args "CVF", Target
  14. Args "-C", Classdir
  15. Args "","."
  16. }
  17. }
  18. Create a new task named Buildlib, dependent build (build is a self-brought task)
  19. Task Buildlib (dependson:[' build ') << {
  20. Makejar ("Volley.jar","Build/intermediates/classes/release")
  21. }
  22. Apply plugin: ' android-library '
  23. Android {
  24. Compilesdkversion
  25. Buildtoolsversion = " a"
  26. sourcesets {
  27. Defaultconfig {
  28. Testpackagename ' com.android.volley.tests '
  29. }
  30. Main {
  31. Assets.srcdirs = [' Assets ']
  32. Res.srcdirs = [' res ']
  33. Aidl.srcdirs = [' src ']
  34. Resources.srcdirs = [' src ']
  35. Renderscript.srcdirs = [' src ']
  36. Java.srcdirs = [' src ']
  37. Manifest.srcfile ' Androidmanifest.xml '
  38. }
  39. Instrumenttest.setroot (' tests ')
  40. InstrumentTest.java.srcDirs = [' tests/src ']
  41. }
  42. }

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

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.