Module相互依赖问题(2018.9.29)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Module相互依赖问题(2018.9.29)相关的知识,希望对你有一定的参考价值。
参考技术A 以电商项目为例 ,项目ModuleA依赖于功能业务ModuleB,业务ModuleB又依赖于核心ModuleC。依赖关系如图所示:2.1. File ——->Project Structure——->Module A(你的module工程)
2.2. 在右边的页签上点击Dependencies,点击右边的“+”添加要导入的工程Module B(这里选择你要导入的module),如图:
先查看Module A的build.gradle中的文件来确认导入是否成功,通常导入成功在
build.gradle中的dependencies中会有compile project(‘:module B’)的字样,如果没有则代表导入不成功。
unspecified on project autolayouttest resolves to an APK archive which is not supported as a compilation dependency XXX等,原因是因为被依赖的ModuleB的此时还是一个Application,从Module B的build.gradle文件里面可以看到:
apply plugin: 'com.android.application'
所以这里要将application改成依赖库的属性,具体如下:
apply plugin: 'com.android.library''
作为一个库不允许设置applicationId,需要将builde.gradle — android — defaultConfig中的applicationId删除:
这时,Module工程的相互依赖导入基本完成,最关键的是,这样比单独导出jar包来用稍微方便点。
Maven项目常见问题:解决相互依赖
问题如下:
INFO] Scanning for projects... [ERROR] The projects in the reactor contain a cyclic reference: Edge between ‘Ve rtex{label=‘org.kuuyee.sample:module-C:1.0-SNAPSHOT‘}‘ and ‘Vertex{label=‘org.ku uyee.sample:module-B:1.0-SNAPSHOT‘}‘ introduces to cycle in the graph org.kuuyee .sample:module-B:1.0-SNAPSHOT --> org.kuuyee.sample:module-A:1.0-SNAPSHOT --> or g.kuuyee.sample:module-C:1.0-SNAPSHOT --> org.kuuyee.sample:module-B:1.0-SNAPSHO T -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectCycleException
解决思路:
检查各种module模块中的pom.xml引入的依赖包,有没有导致相互依赖的,造成循环依赖问题。
以上是关于Module相互依赖问题(2018.9.29)的主要内容,如果未能解决你的问题,请参考以下文章
IDEA中module之间相互引用,必须要install到本地的解决方案