AndroidStudio建立lib工程並導出jar包

第一種方式

1.建立一個工程,選擇AndroidApplicationandroid

2.建立一個module選擇Android Libraryapp

3.修改Library module的build.gradle文件,添加一下任務gradle

//task to delete the old jar
task deleteOldJar(type: Delete) {
    delete 'release/dynamicload.jar'
}

//task to export contents as jar
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    ///Rename the jar
    rename('classes.jar', 'dynamicload.jar')
}

exportJar.dependsOn(deleteOldJar, build)

4.打開Gradle面板,選擇Tasks->Other->exportJar,並執行。ui

若是執行成功,會獲得dynamicload.jarspa

 

第二種方式

1.建立一個工程,選擇AndroidApplicationip

3.修改Library module的build.gradle文件,get

io

apply plugin: 'com.android.application'

修改成class

apply plugin: 'com.android.library'

 

defaultConfig修改成module

defaultConfig {
    minSdkVersion 24
    targetSdkVersion 25
}

 

添加一下任務

//task to delete the old jar
task deleteOldJar(type: Delete) {
    delete 'release/dynamicload.jar'
}

//task to export contents as jar
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    ///Rename the jar
    rename('classes.jar', 'dynamicload.jar')
}

exportJar.dependsOn(deleteOldJar, build)

4.打開Gradle面板,選擇Tasks->Other->exportJar,並執行。

若是執行成功,會獲得dynamicload.jar

 

另外一段腳本

引入assets和meta-inf文件
//打jar包
def SDK_BASENAME = "SkyDataReportImpl";
def sdkJarPath = "build";
def zipFile = file('build/intermediates/bundles/release/classes.jar')

task deleteOldJar(type: Delete) {
    delete 'build/SkyDataReportImpl.jar'
}

task makeJar(type: Jar) {     from zipTree(zipFile)     from fileTree(dir: 'src/main', includes: ['assets/**','META-INF/versioninfo.properties'])     baseName = SDK_BASENAME     destinationDir = file(sdkJarPath) } makeJar.dependsOn(deleteOldJar,build)

相關文章
相關標籤/搜索