Android Module引用另一个Module,却无法使用里面的依赖库

栏目: 服务器 · 发布时间: 7年前

内容简介:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011133213/article/details/86262031

版权声明:本文为博主原创文章,未经博主允许不得转载。 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'

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Weaving the Web

Weaving the Web

Tim Berners-Lee / Harper Paperbacks / 2000-11-01 / USD 15.00

Named one of the greatest minds of the 20th century by Time , Tim Berners-Lee is responsible for one of that century's most important advancements: the world wide web. Now, this low-profile genius-wh......一起来看看 《Weaving the Web》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具