【Android】多模块工程移动目录编译报错:Could not determine the dependencies of task ‘:app:compileDebugJavaWithJavac‘

1 背景

事情是这样的,最近在利用组件化的方式开发一个多模块工程,看着模块越来越多,于是想把某些同一层级的模块放到同一个目录下,如下:
在这里插入图片描述

可以直接将相应模块拖动到目标目录下,也可以如下所示,在模块上右键,选择move directory移动路径
在这里插入图片描述

2 问题

本以为只是移动一个路径而已,其他的Android Studio都会帮我们处理好,无需额外操作,结果移动之后发现项目编译失败,报错信息如下:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :limu_music.
     Required by:
         project :app
      > No matching configuration of project :limu_music was found. The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - None of the consumable configurations have attributes.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

关键信息在:No matching configuration of project :limu_music was found.

于是去网上搜了一圈,但没找到什么有效的解决方案,对gradle还是太陌生了,虽然平时天天和它打交道,但是一直没有好好的去学习相关的一些知识。
在这里插入图片描述

3 解决方法

就在随便翻一翻桌边那本gradle书籍时,还真有了一些发现,看到了setting.gradle的相关配置。
在这里插入图片描述
可以看到,我们在setting.gradle中定义了很多子项目,但是并没有配置具体的项目路径,此时gradle会默认这些子项目的路径是setting.gradle文件的同级目录,所以才能找到我们相关子项目。

但是上面我移动了项目路径,导致同级目录找不到相关项目。从上面的报错信息也可以看到,No matching configuration of project :limu_music was found.,大概就是模块的配置文件没找到,这才导致了标题中的问题出现。

解决这个报错只需要我们手动指定相应项目的路径即可,提供一下几个方法:

(1)在include时指定路径
setting.gradle文件中在include模块时带上目录,这里的business就是这个模块的父目录,:就相当于\
在这里插入图片描述
另外,在壳工程/其它模块中引入该模块时也需如此,带上模块路径

implementation project(':business:limu_music')

(2)配置项目是指定具体的路径
这种方法在依赖相关模块时和之前一样,只需要指定模块名称

implementation project(':limu_music')

只需要在setting.gradle中配置模块目录:
在这里插入图片描述
图中四种方式都是可以的,任选一种即可,此时重新编译就没什么问题了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柳木头

谢谢小兄弟^0^

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值