Androidstudio Exporting Jar Packages

Source: Internet
Author: User

Androidstudio Export Jar Package-Android-cubic Cube Network-computer knowledge and technology interactive exchange platform

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 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:

View Sourceprint? 01. buildscript { 02. ????repositories { 03. ????????mavenCentral() 04. ????} 05. ????dependencies { 06. ????????classpath ‘com.android.tools.build:gradle:0.12.+‘ 07. ????} 08. } 09. apply plugin: ‘com.andriod.library‘ 10. ? 11. android { 12. ????compileSdkVersion 19 13. ????buildToolsVersion = "20" 14. ? 15. ????sourceSets { 16. ????????defaultConfig { 17. ????????????testPackageName ‘com.android.volley.tests‘ 18. ????????} 19. ? 20. ????????main { 21. ????????????assets.srcDirs?????? = [‘assets‘] 22. ????????????res.srcDirs????????? = [‘res‘] 23. ????????????aidl.srcDirs???????? = [‘src‘] 24. ????????????resources.srcDirs??? = [‘src‘] 25. ????????????renderscript.srcDirs = [‘src‘] 26. ????????????java.srcDirs???????? = [‘src‘] 27. ????????????manifest.srcFile ‘AndroidManifest.xml‘ 28. ? 29. ????????} 30. ? 31. ????????instrumentTest.setRoot(‘tests‘) 32. ????????instrumentTest.java.srcDirs = [‘tests/src‘] 33. ????} 34. }

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:

View Sourceprint? 1. ?View Sourceprint? 01. buildscript { 02. ????repositories { 03. ????????mavenCentral() 04. ????} 05. ????dependencies { 06. ????????classpath ‘com.android.tools.build:gradle:0.12.+‘ 07. ????} 08. } 09. ? 10. //定义一个函数,target是生成jar包的文件名,classDir是class文件所在的文件夹 11. def makeJar(String target,String classDir){ 12. ????exec{ 13. ????????executable "jar"?? //调用jar 14. ????????args "cvf",target 15. ????????args "-C", classDir 16. ????????args "","." 17. ? 18. ? 19. ????} 20. } 21. ? 22. //新建一个task,名为buildLib,依赖build(build是一个自带的task) 23. task buildLib(dependsOn:[‘build‘])<< { 24. ????makeJar("volley.jar","build/intermediates/classes/release") 25. ? 26. ? 27. } 28. ? 29. ? 30. apply plugin: ‘android-library‘ 31. ? 32. ? 33. android { 34. ????compileSdkVersion 19 35. ????buildToolsVersion = "20" 36. ? 37. ? 38. ????sourceSets { 39. ????????defaultConfig { 40. ????????????testPackageName ‘com.android.volley.tests‘ 41. ????????} 42. ? 43. ? 44. ????????main { 45. ????????????assets.srcDirs ? ? ? = [‘assets‘] 46. ????????????res.srcDirs ? ? ? ? ?= [‘res‘] 47. ????????????aidl.srcDirs ? ? ? ? = [‘src‘] 48. ????????????resources.srcDirs ? ?= [‘src‘] 49. ????????????renderscript.srcDirs = [‘src‘] 50. ????????????java.srcDirs ? ? ? ? = [‘src‘] 51. ????????????manifest.srcFile ‘AndroidManifest.xml‘ 52. ? 53. ? 54. ????????} 55. ? 56. ? 57. ????????instrumentTest.setRoot(‘tests‘) 58. ????????instrumentTest.java.srcDirs = [‘tests/src‘] 59. ????} 60. }

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.

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.