Android Studio build dex jar

來源:互聯網
上載者:User

標籤:

 

Gradle配置

Build設定檔gradle.build中添加如下task

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)

 

此方法是直接從把gradle build產生的classes.jar拷貝到指定目錄並且重新命名,必須依賴build task。

修改dex jar的MANIFEST.MF檔案

由於目前gradle的”com.android.application/library”不能和”java” plugin同時使用,所以我們可以使用其他方法來修改,本文中使用python的zipfile來處理。

自訂MANIFEST.MF檔案

檔案內容如下:

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指令碼

例如:建立一個python指令碼,命名為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()

 

執行python的shell指令碼(mac/linux)/批次檔(win)win

建立一個檔案命名updateJar.bat檔案內容為python updateJarManifest.py

mac/linux

建立一個檔案命名為:updateJar.sh,

檔案內容為:

#!/bin/bash#@author Leo.Kang# 2015-4-15 20:47python ./ updateJarManifest.py

  

更新build.gradle 配置
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.