Android Studio Packs Module into a Jar package

Source: Internet
Author: User

Organize records Androidstudio Package A module project into a jar package.

First, you need to modify the Build.gradld file in the module project you want to package, such as:
  

Next, add the following code to the Build.gradle file:

task Clearjar (type:delete) {Delete ' libs/sdk.jar '//The SDK is the name of your own jar package, which is literally named} task Makejar (Type:org.gradle.api.tasks.bundling.Jar) {//Specify the generated jar namebaseName ' SDK '//Where to package the class fileFrom (' build/intermediates/classes/debug/org/cmdmac/cloud/pluginsdk/')//directory structure after packaging to jarInto (' org/cmdmac/cloud/pluginsdk/')//Remove directories and files that do not need to be packagedExclude (' test/', ' buildconfig.class', ' R.class')//Remove files starting with Rexclude{it.name.startsWith (' R ');}} Makejar.dependson (Clearjar, build)

Note: These configurations are to be paired with android{...} These configured scripts are in a lateral relationship, never write to android{...} to the.

3, switch to the CMD in Windows, cut to your project path, such as my project path is F:\AndroidStudioProjects\MyApplication\app
Then cut to the path to the directory and enter: Gradle Makejar
as follows:

If prompted: The Gradle command is not available. Then you need to add the variables in your system environment variables:

Where the variable value in Gradle_hom is your gradle path.

Then, at the end of the Path property, add ";%gradle_home%\bin", as follows:

Note: This path must also be edited in the user variable, which I then edited in the system variable, and the dead and Alive configuration was unsuccessful.

After saving, enter gradle-v in your cmd if the configuration is successful, there will be some information about the Gradle version, such as:

Then cut to the path of your project and enter Gradle Makejar:

The following results will appear,

We are prompted to configure the following script in the Bulid.gradle file:
lintoptions {
Abortonerror false
}

Note: This sentence should be written in android{...} configuration inside

Configured SYSN now once the project, run the cmd input again: Gradle Makejar
You will see the following result:

Well, here's the point that our task is complete and we can see the. jar file we named under the Build/libs folder of the project module, as follows:

Android Studio Packs Module into a Jar package

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.