gradle 语法备用

目的仅为记录 gradle 的相关语法, 以备下次使用时不需要再查找

 

一、exclude语法,  排除某库的传递依赖

1、带 group名称的

 

compile ("cn.mucang.android.mucang.framework:core:${coreVersion}"){

        exclude group: 'cn.mucang.android.framework', module: 'android-core-jni'

    }

 

2、直接通过 module 名称来 移除的

compile('com.facebook.fresco:fresco:0.10.0') {

       exclude module: 'support-v4'
}

 

3、如果是源码形式(lib中放jar包)引入的开源库: (未验证)

 

compile (project(':thirdpart:RecyclerViewAdapterLibrary')){ 
     exclude group: 'com.android.support' 
}

 

二、强制依赖某库
2.1  gradle 早期版本中,force强制依赖某版本的库的写法
compile("groupName:moduleName:27.1.1") {
        force true
    }
2.2  gralde 新版本中(gradle plugin 3.0之后 的版本)
  在app module 的 build.gralde中 


android {
    compileSdkVersion project.androidsdk.compileSdkVersion
    buildToolsVersion project.androidsdk.buildToolsVersion


    defaultConfig {
        applicationId "cn.mucang.android.voyager"
        targetSdkVersion project.androidsdk.targetSdkVersion
        minSdkVersion project.androidsdk.minSdkVersion
        versionCode 500010604
        versionName "${appVersionName}"
    }

    configurations.all {
        resolutionStrategy.force "cn.mucang.android.mucang.framework:core:${coreVersion}"
        resolutionStrategy {
            force "cn.mucang.android.mucang.framework:core:${coreVersion}"
        }
    }
}

 

三、查询项目app module的全部完整依赖树,从当前项目(根)延伸到各叶子节点(库)

./gradlew :app:dependencies

其中app是你的module的名称.

 

./gradlew :app:dependencies --configuration compile

./gradlew :app:dependencies --configuration debugRuntimeClasspath

./gradlew :app:dependencies --configuration releaseRuntimeClasspath

 

 

四、单独查看某一个名称库的路径,可以显示该库的多个版本的引入关系

 

./gradlew :app:dependencyInsight --dependency okhttp --configuration compile

 

 

 

 

 

五、关于新版本gradle中的 complie、api、implementation的选择

在Android Studio 2.x 的版本中, 只有 complie ,默认为传递依赖,      依赖库的版本号后加@aar为非传递依赖

但在AS 3.x的版本中,compile即将被废弃,警告会提示在2018年底彻底移除, 改为 api和 implementation, api 完全等同于原来的compile不加@aar,即传递依赖;   implementation 等同于 compile 加@aar,即非传递依赖。

更新时,建议根据旧版本中是否为传递依赖,来决定是用api替换、还是用implementation替换。

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值