android 动态加载classpath,Android Gradle dependencies 方式:classpath、implementation、api 的区别...

classpath:一般是添加 buildscript 本身需要运行的东西,buildScript是用来加载gradle脚本自身需要使用的资源,可以声明的资源包括依赖项、第三方插件、maven仓库地址等。

某种意义上来说,classpath 声明的依赖,不会编译到最终的 apk 里面。buildscript {

repositories {

google()

jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:2.3.3'

//butterknife注入

classpath 'com.jakewharton:butterknife-gradle-plugin:8.2.1'

}

}implementation、api :在模块中的build.gradle中,给 dependencies 中添加的使应用程序所需要的依赖包,也就是项目运行所需要的东西。implementation:对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开。

api:对比 implementation,不会隐藏。(等同于 Android Gradle 2.x 版本的 compile(已deprecated))

如果 lib C 依赖了lib A 2.0版本,lib B implementation依赖了lib A 1.0版本:

那么编译期,libC 可访问2.0版本的libA ,libB可访问1.0版本的libA。但最终打到apk中的是2.0版本(通过依赖树可看到)。

在运行期,lib B 和lib C都可访问lib A的2.0版本(因为apk的所有dex都会放到classLoader的dexPathList中)。android {...}

...

dependencies {

// The 'compile' configuration tells Gradle to add the dependency to the

// compilation classpath and include it in the final package.

// Dependency on the "mylibrary" module from this project

api project(":mylibrary")

// Remote binary dependency

implementation 'com.android.support:appcompat-v7:27.1.1'

// Local binary dependency

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

implementation 'com.jakewharton:butterknife:8.2.1'

annotationProcessor 'com.jakewharton:butterknife-compiler:8.2.1'

}

更多信息参考:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值