Androidstudio生成aar 和 jar (生产jar包含第三方的jar ,比如tsp.jar包含okhttp.jar) 以及 Module build.gradle引入aar资源

Androidstudio生成aar

代码能编过情况下, AS菜单栏Build---Rebuild Project  (或者make project )  就可以生产AAR

aar目录在  库 /build/outputs/aar/libraryname.aar


Module build.gradle引入aar资源

①.将aar包复制到lib目录下 

②.配置build.gradle文件:

加入

  repositories {
        flatDir {
        dirs 'libs'
    }

compile(name:'camerascan-1.0', ext:'aar')


Androidstudio 生成jar

代码能编过情况下, AS菜单栏Build---Rebuild Project  (或者make project )  就可以生产jar

目录 manager/build/intermediates/bundles/debug/classes.jar


*.jar: 只包含了class文件与清单文件 ,不包含资源文件,如图片等所有res中的文件。

*.aar: 包含所有资源 ,class以及res资源文件全部包含

解压jar 会发现, module-libs 中的第三方的jar 不在classes.jar 中

如果提供别人使用,要求把第三方的jar 打入jar 包中.

生产jar包含第三方的jar

在module的build.gradle 中增加如下task


task makeJar(type: Jar) {
    archiveName = 'tsp.jar'        //生成的新jar名称
    from(project.zipTree('build/intermediates/intermediate-jars/debug/classes.jar'))    module生成的jar 目录
    from (project.zipTree('libs/converter-gson-2.1.0.jar'))  //要打入的各种第三方jar
    from (project.zipTree('libs/gson-2.6.2.jar'))
    from (project.zipTree('libs/okhttp-2.0.0.jar'))
    from (project.zipTree('libs/okio-1.9.0.jar'))
    from (project.zipTree('libs/okhttp-urlconnection-2.0.0.jar'))
    from (project.zipTree('libs/okhttp-3.4.1.jar'))
    from (project.zipTree('libs/retrofit-2.1.0.jar'))
    from (project.zipTree('libs/retrofit-1.8.0.jar'))
    destinationDir = file('build/libs')                             //生成jar 目录
}
一,首先生成classes.jar   make project

二. 点击Androidstudio 右上角  Gradle

展开module -- other---makeJar  双击makeJar  , 等待下,就会生产包含了第三方jar 的jar包

Android Studio 里面的引用第三方库

方式:1:它就会自动把这个包下载下来,并且引用它。节省git空间,而且修改版本也很方便。

compile 'com.android.support:support-v4:23.3.0'

方式2:引用libs下所有jar包

compile fileTree(dir: 'libs', include: ['*.jar'])

方式3:引用一个jar

compile files('libs/fastjson-1.1.53.android.jar')

方式4:引用一个aar文件,注意并不能像 方式2 那样自动引用全部的aar,而需要对每个aar分别进行引用。

compile(name: 'aar_file_name', ext: 'aar')

方式5:引用库类型的项目

compile project(':xxxsdk')

方式6:仅仅在编译时使用,但最终不会被编译到apk或aar里

provided files('libs/glide-3.7.0.jar')


例子:

repositories {
    flatDir {
        dirs 'libs/'                                          //指定目录: module中的libs
        dirs '../../../../OUT_APP/lib'                 //项目其他目录
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')                    //引用libs下所有jar包    
    provided fileTree(include: 'QGAPI.jar', dir: '../../../../sdk_release')                //动态引用jar , 此种方式不会把jar 打入APK
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'                       //引用在线jar
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile(name: 'recyclerview-v7-25.1.1', ext: 'aar')                           // 引用aar
    compile(name: 'GeelyWidget-release', ext: 'aar')
    compile(name: 'ThemeMgr-release', ext: 'aar')
    compile 'com.github.bumptech.glide:glide:4.0.0'
    compile fileTree(include: 'persistentcookieJar.jar', dir: '../../../../vendor/tsp_jar')             //引用指定目录中的jar
    compile fileTree(include: 'tspapi.jar', dir: '../../../../sdk_release')
    compile 'com.android.support:multidex:1.0.0'
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值