1. 程式人生 > >Android Studio封裝SDK,排除類的小坑

Android Studio封裝SDK,排除類的小坑

第一種方式

def SDK_PREFIXNAME = "sdk_name";//打包後名字
def SDK_VERSION = "_version101";//SDK版本號
def SDK_NAME = SDK_PREFIXNAME + SDK_VERSION + ".jar";
def zipFile = file('build/intermediates/packaged-classes/release/classes.jar')
def sdkDestinationPath = "build/lib_sdk/";//儲存目錄

task makeJar(type: Jar) {//生成jar
    //如果之前存在,則先刪除
delete sdkDestinationPath + SDK_NAME from zipTree(zipFile) //去掉不需要打包的目錄和檔案(絕對路徑) exclude('com/example/andriod/myapplication/remove', 'RemoveUtils.class', 'RemoveTextUtils.class') from fileTree(dir: 'src/main', includes: ['assets/**']) baseName = SDK_PREFIXNAME + SDK_VERSION destinationDir =
file(sdkDestinationPath) } makeJar.dependsOn(build)

第二種方式

def SDK_PREFIXNAME = "sdk_name";//打包後名字
def SDK_VERSION = "_version101";//SDK版本號
def SDK_NAME = SDK_PREFIXNAME + SDK_VERSION + ".jar";
def sdkDestinationPath = "build/lib_sdk/";//儲存目錄

task makeJar(type: Copy) {//生成jar
    //如果之前存在,則先刪除
    delete sdkDestinationPath +
SDK_NAME //設定拷貝的檔案 from('build/intermediates/packaged-classes/release/classes.jar') //生成jar包後的檔案目錄位置 into(sdkDestinationPath) //去掉不需要打包的目錄和檔案(絕對路徑) exclude( 'com/example/andriod/myapplication/remove/RemoveUtils.class' , 'com/example/andriod/myapplication/remove/RemoveTextUtils.class') //include,exclude 引數來設定過濾 include('classes.jar') //重新命名 rename('classes.jar', SDK_NAME) } makeJar.dependsOn(build)