版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011133213/article/details/86262031
比如我们现在有一个App模块设计为:
主工程: app
模块: ui , framework
引入模块的方式:在settings.gradle中,指定正确的模块路径
include ':app', ':framework', ':ui'
project(':framework').projectDir = new File('../framework')
project(':ui').projectDir = new File('../ui')
如果现在framework引入了一些依赖库,假设如下:
// Retrofit 网络框架依赖
implementation "com.squareup.retrofit2:retrofit:2.5.0"
// Gson 依赖
implementation 'com.google.code.gson:gson:2.8.5'
// ARouter解耦框架
implementation 'com.alibaba:arouter-api:1.4.1'
annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'
如果这样写的话,主工程app中将无法调用到这些依赖库中的类。
因为implementation声明的依赖只能在本module模块内使用,跨module使用就要使用api声明!!改成如下即可
// Retrofit 网络框架依赖
api "com.squareup.retrofit2:retrofit:2.5.0"
// Gson 依赖
api 'com.google.code.gson:gson:2.8.5'
// ARouter解耦框架
api 'com.alibaba:arouter-api:1.4.1'
annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'