Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.

最近在revert一个library的build文件夹的时候,SVN出现错误,提示操作失败。
结果整个Android Studio就开始不正常了。
一直提示:

Compilation is not supported for following modules: xxx. Unfortunately
you can’t have non-Gradle Java modules and Android-Gradle modules in
one project.

既然gradle的问题,那就同步一下吧。
结果发现左上角的Sync Project with Gradle Files按钮竟然是灰色的:
在这里插入图片描述
无法点击,怎么办?

解决方案

于是想到万能大法,File – Invalidate Caches / Restart.
结果AS重启后,仍然报上面那个错误。
又想到既然提示非Gradle项目,那么一定有相关的配置文件,让IDE去读取,从而判断是不是Gradle项目。
每个module都有一个.iml文件,这是IDE自动生成的,一般不需要我们去关注和修改。google一下对iml file的解释:

Module file created by IntelliJ IDEA, an IDE used to develop Java
applications; stores information about a development module, which may
be a Java, Plugin, Android, or Maven component; saves the module
paths, dependencies, and other settings.

     IML files are used for storing smaller sections of a larger development project. IntelliJ IDEA uses .IPR files for storing

projects, which may reference multiple IML files. Both IPR and IML
files use XML formatting.

IML file also refers to

IntelliJ IDEA Module - Module file for IntelliJ IDEA, also is a text
file which could be opened in text editor. The developer or
automatically generated by the IntelliJ program can creat the IML
files, they can also be generated by third-party programs such as
Maven with the IDEA plugin.

接着,打开有问题的module的iml文件,发现里面只有简单的几行代码。
对比另一个module的iml文件,发现少了不少内容。
这就简单了,把没有问题的iml文件内容拷贝过来,里面改成自己module的名字,然后再使用File – Invalidate Caches / Restart大法,一切正常!

猜你喜欢

转载自blog.csdn.net/ddnosh/article/details/86513313
今日推荐