错误:Unfortunately you can‘t have non-Gradle Java modules and Android-Gradle modules in one project.

  • Post author:
  • Post category:java



我的新书


《Android App开发入门与实战》


已于2020年8月由人民邮电出版社出版,欢迎购买。

点击进入详情


最近在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大法,一切正常!



版权声明:本文为ddnosh原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。