These two days the company wants to restructure the project, the previous project on Eclipse, ready to migrate to Android studio, and the need to package the project, so I learned gradle packaged content in Android studio. I am in the company of the Mac, in the home of Windows, two platforms, packaging basically the same, here is mainly under the MAC system process.
Terminal in Andorid Studio uses a Mac terminal, so to package with terminal's Gradle command, first configure the Gradle environment in your Mac to open the terminal on your Mac:
(1) Input command: Open. Bash_profile
(2) If you are prompted to do not have a. base_profile file, create the. bash_profile file first.
Create the. bash_profile file:
Input: Thetouch. Bash_profile command will help you create and open the. bash_profile file
(3) Edit in open. bash_profile file, here is my content:
export gradle_home=/users/wuqiyan/downloads/software/gradle-2.12; (download gradle-2.12, unzip the directory)
Export path= $PATH: $GRADLE _home/bin
After you save it.
(4) Re-enter the command: Open. Bash_profile opens the. bash_profile file.
(5) After the completion of the process, the GRADLE environment is well configured. Check, enter the command: gradle-version see below is equal to the configuration.
------------------------------------------------------------
Gradle 2.12
------------------------------------------------------------
Build time:2016-03-14 08:32:03 UTC
Build Number:none
Revision:b29fbb64ad6b068cb3f05f7e40dc670472129bc0
groovy:2.4.4
Ant:apache Ant (TM) version 1.9.3 compiled on December 23 2013
Jvm:1.8.0_77 (Oracle Corporation 25.77-b03)
Os:mac OS X 10.11.3 x86_64
The above is the Gradle configuration in Mac, this time back to Android studio, enter the command in Terminal: Gradle-version will also see the above hint.
First look at the directory structure:
After you have built a project, open the Build.gradle file under the app:
(1) Change Apple plugin: ' com.android.application ' to apply plugin: ' Com.android.library '
(2) Delete: Applicationid,versioncode,versionname
(3) Add:
task Clearjar (type:delete) {//Delete PreviousDelete'Build/libs/partjar.jar'}task Makejar (type:copy) {//where to package class files, you can specify files and directories from('build/intermediates/bundles/debug/') //directory structure after packaging to jarInto'build/libs/') include ('Classes.jar') Rename ('Classes.jar','Partjar.jar')} makejar.dependson (Clearjar, build)
After the code is entered, enter in terminal in Andriod Studio:./gradlew makejar (Input in Windows: Gradlew Makejar)
Finally, you can find the Partjar.jar in the build/libs/directory.
If you want to hit the jar to specify the package name and class, you can refer to the following code:
task Clearjar (type:delete) {Delete'Build/libs/partjar.jar'}task Makejar (type:org.gradle.api.tasks.bundling.Jar) {//Specify the generated jar nameBaseName'partJar2' //where to package class files, you can specify files and directories from('build/intermediates/classes/debug/com/example/wuqiyan/exportjar/') {include'Buildconfig.class' } //directory structure after packaging to jarInto'com/example/wuqiyan/exportjar/')}makejar.dependson (clearjar,build)
Can read: http://www.alloyteam.com/2015/03/shi-yong-gradle-da-bao-zhi-ding-bao-ming-he-lei-di-jar/
HTTP://WWW.JIANSHU.COM/P/DC6BCD4478A1
Use Gradle in Android studio to hit the Jar pack (under Mac)