Android Studio build dex jar

Source: Internet
Author: User
Tags python script

Gradle Configuration

Add the following task to the build configuration file Gradle.build

Task Clearjar (type:delete) {    Delete ' Build/outputs/mylib.jar '}task Copyjar (type:copy) {from    (' build/ intermediates/bundles/release/') into    (' build/outputs/libs/')    include (' Classes.jar ')    rename (' Classes.jar ', ' Mylib.jar ')}copyjar.dependson (Clearjar, build)

This method is copied directly from the Classes.jar generated by the Gradle build to the specified directory and renamed, and must depend on the build task.

Modify the MANIFEST.MF file for the Dex jar

Since the current Gradle "com.android.application/library" cannot be used in conjunction with the "Java" plugin, we can use other methods to modify it, and this article uses Python's zipfile to handle it.

Customizing the MANIFEST.MF file

The contents of the file are as follows:

Manifest-version:1.0gradle-version:2.2.1created-by:1.8.0_20-b26 (Oracle Corporation) Date:2015-4-15author: leo.kangjar-version:1.0.0

  

Python script

For example: Create a new Python script named updatejarmanifest.py

#!/usr/bin/pythonimport sys,zipfile,shutil,osdef Generate ():       jar_file = "./Mylib_temp.jar"       Target_jar = Os.path.dirname (jar_file) + "/mylib.jar"       shutil.copy (Jar_file, Target_jar)       zipped = ZipFile. ZipFile (Target_jar, ' a ', ZipFile. zip_deflated)       content_file = "meta-inf/manifest. MF "       mf_file ="./manifest. MF "       zipped.write (Mf_file, Content_file)       zipped.close ()       return target_jargenerate ()

Execute Python shell script (mac/linux)/batch file (win) win

Create a new file name Updatejar.bat file contents as Python updatejarmanifest.py

Mac/linux

Create a new file named: updatejar.sh,

The contents of the file are:

#!/bin/bash# @author leo.kang# 2015-4-15 20:47python./updatejarmanifest.py

  

Update Build.gradle Configuration
Task Clearjar (type:delete) {    Delete ' Build/outputs/mylib.jar '} task Copyjar (type:copy) {from    (' build/ intermediates/bundles/release/') into    (' build/outputs/libs/')    include (' Classes.jar ')    rename (' Classes.jar ', ' Mylib_temp.jar ')}copyjar.dependson (Clearjar, build) Releasejar.dependson (Clearjar, build) task Execpython (type:exec) {    //workingdir file ('./')    commandLine './updatejar.sh '}execpython.dependson ( Releasejar)

Reference

Http://gradle.org/docs/current/dsl/org.gradle.api.tasks.Exec.html

Android Studio build dex jar

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.