错误:不幸的是,一个项目中不能有非 Gradle Java 模块和 > Android-Gradle 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30142056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Unfortunately you can't have non-Gradle Java modules and > Android-Gradle modules in one project
提问by kamokaze
I have an IntelliJ 14.1.2 Project consisting of two modules - one is an Android Gradle based module and the other is a Spring Java-based module with Maven.
我有一个由两个模块组成的 IntelliJ 14.1.2 项目 - 一个是基于 Android Gradle 的模块,另一个是带有 Maven 的基于 Spring Java 的模块。
gps-trackman.v1 is my root project and I've not configured any outputs or facets for this project. The app is my android gradle module and I've configured Android and Android-Gradle Facet for this project and gps-trackman isn't my Spring Maven Project. I want to be able to build everything all together. Is it possible?
gps-trackman.v1 是我的根项目,我没有为此项目配置任何输出或方面。该应用程序是我的 android gradle 模块,我已经为这个项目配置了 Android 和 Android-Gradle Facet,而 gps-trackman 不是我的 Spring Maven 项目。我希望能够一起构建所有东西。是否可以?
I now get this error message in my IntelliJ Eventlog
我现在在 IntelliJ 事件日志中收到此错误消息
Unsupported Modules Detected: Compilation is not supported for following modules: gps-trackman, gps-trackman.v1, app. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
The project 'gps-trackman.v1' is not a Gradle-based
检测到不支持的模块:以下模块不支持编译:gps-trackman、gps-trackman.v1、app。不幸的是,一个项目中不能有非 Gradle Java 模块和 Android-Gradle 模块。
项目“gps-trackman.v1”不是基于 Gradle 的
Is this error just due to a misconfiguration of my project or is it really not possible to have a maven module and a Gradle module in one project?
这个错误是因为我的项目配置错误还是真的不可能在一个项目中同时拥有一个 Maven 模块和一个 Gradle 模块?
Do I have to configure any Facets for the root project? Alternatively, do I have to convert my maven to gradle?
我是否必须为根项目配置任何方面?或者,我是否必须将我的 Maven 转换为 gradle?
回答by Jagruttam Panchal
First of all you should update to Android Studio Source: https://code.google.com/p/android/issues/detail?id=77983
首先你应该更新到 Android Studio 来源:https: //code.google.com/p/android/issues/detail?id=77983
Then you should go to File -> Invalidate Caches / Restart -> Invalidate Caches & Restart.
然后你应该去 File -> Invalidate Caches / Restart -> Invalidate Caches & Restart。
Then try to build the application again.
然后再次尝试构建应用程序。
I found this answer here
我在这里找到了这个答案
回答by Mohamd Ali
the error explain all things, the idea is confused between gradleand maven.
错误解释了所有事情,这个想法在gradle和maven之间混淆。
try to create new project with two gradlemodules, you can build spring application with gradle as maven.
尝试使用两个gradle模块创建新项目,您可以使用 gradle 作为 maven 构建 spring 应用程序。
see thisexample from spring guides
从弹簧指南看到这个例子
回答by Region39
Press Ctrl-Alt-S > Uncheck "Android Support" plugin
按 Ctrl-Alt-S > 取消选中“Android 支持”插件
(I wish I could tell you exactly why this works, but I can't. If you want to develop for Android, try using Android Studio, which is also made by Jetbrains.)
(我希望我能确切地告诉你为什么会这样,但我不能。如果你想为 Android 开发,请尝试使用 Android Studio,它也是由 Jetbrains 制作的。)
回答by Egor Neliuba
Make sure you have added your module to the settings.gradle
file:
确保您已将模块添加到settings.gradle
文件中:
include ':app'
include ':your-module'
回答by dirkvranckaert
Had same issue with Android Studio 3.3 Canary 13.
与 Android Studio 3.3 Canary 13 有同样的问题。
I was able to solve it by following these steps:
我能够通过以下步骤解决它:
- Go to the module settings and remove your module from the list
- Edit settings.gradle and remove your module from there also
- Physically move the module directory out of the project (to your desktop for instance)
- Then in the module settings again add a module and select as type 'Import Gradle Project' in which you select the module folder you have moved to your desktop (or anywhere else)
- 转到模块设置并从列表中删除您的模块
- 编辑 settings.gradle 并从那里删除你的模块
- 物理地将模块目录移出项目(例如到您的桌面)
- 然后在模块设置中再次添加一个模块并选择“导入 Gradle 项目”类型,您可以在其中选择已移动到桌面(或其他任何地方)的模块文件夹
When you complete these steps the module will be copied into your project again, AS will start syncing Gradle again and that succeeds without errors :-) Check your GIT status and you will see as soon as you add your module directory to GIT again that nothing has changed to your working directory. So it's purely an issue with AS that gets somehow out-of-sync...
当您完成这些步骤后,模块将再次复制到您的项目中,AS 将再次开始同步 Gradle,并且成功且没有错误:-) 检查您的 GIT 状态,您将在再次将模块目录添加到 GIT 时看到什么都没有已更改为您的工作目录。所以这纯粹是 AS 以某种方式不同步的问题......
Based my solution on this comment: https://issuetracker.google.com/issues/37008041#comment3
基于此评论我的解决方案:https: //issuetracker.google.com/issues/37008041#comment3
回答by Tom Rutchik
For me, my project was very corrupted. I don't know how I got into that state. What I observed was that several .gradle file and proguard file had a whole bundle of xml content. Fortunately, the physical file had the correct content in it, but android studio was displaying it as some xml file that looked like it belonged to some generated res xml data. Things like "Sync to file system" or "sync project to gradle file", "invalidate cache and restart" or "gradlew clean" wouldn't clear up the issue. I even replaced the bogus xml data being displayed in the gradle scripts with the original content, but that didn't help either. I tried some of the advise given above, but they either didn't work or seemed too complex for me to feel that me project would go back into a well formed state.
对我来说,我的项目非常损坏。我不知道我是怎么进入那种状态的。我观察到的是,几个 .gradle 文件和 proguard 文件有一整套 xml 内容。幸运的是,物理文件中包含正确的内容,但 android studio 将其显示为某个 xml 文件,看起来它属于某些生成的 res xml 数据。诸如“同步到文件系统”或“将项目同步到 gradle 文件”、“使缓存无效并重新启动”或“gradlew clean”之类的内容无法解决问题。我什至用原始内容替换了 gradle 脚本中显示的虚假 xml 数据,但这也无济于事。我尝试了上面给出的一些建议,但它们要么不起作用,要么看起来太复杂了,我觉得我的项目会回到一个良好的状态。
So I elected to create a new blank project. Using file explorer, I copied all of the modules in the corrupted project into the new project (a plain old copy and paste) I also replaced the "settings.gradle" and the root "build.gradle" files of the new file with the contents from the old file. Once that is done, you have to run "sync Project with gradle files and you're good to good. If by chance your project root has some content that you physically added, you would have to copy that over too.
所以我选择创建一个新的空白项目。使用文件资源管理器,我将损坏项目中的所有模块复制到新项目中(一个普通的旧复制和粘贴)我还用新文件的“settings.gradle”和根“build.gradle”文件替换了旧文件中的内容。完成后,您必须运行“将项目与 gradle 文件同步,这样就很好了。如果您的项目根目录有一些您物理添加的内容,您也必须将其复制过来。
So that gets you back up and working. I don't know for sure what caused my project to get corrupted, but I think it might have to do with the laptop going into sleep mode. My laptop was not allowing me wake up from sleep and the only way for me to wake up was to power off an power on again. I did have some projects opened a few times when that happened. So that's my best guess as to how the project might have gotten corrupted.
这样你就可以重新开始工作。我不确定是什么导致我的项目损坏,但我认为这可能与笔记本电脑进入睡眠模式有关。我的笔记本电脑不允许我从睡眠中醒来,我醒来的唯一方法是再次关闭电源。发生这种情况时,我确实打开了几次项目。所以这是我对项目可能如何被破坏的最佳猜测。
回答by ahmednabil88
回答by Ashutosh dwivedi
This solution worked for me Android Studio 3.3.2.
这个解决方案适用于我的 Android Studio 3.3.2。
- Delete the .iml file from the project directory.
- In android studio File->invalidate caches/restart.
- Clean and Rebuild project if the auto build throws error.
- 从项目目录中删除 .iml 文件。
- 在 android studio File->invalidate caches/restart。
- 如果自动构建引发错误,则清理并重建项目。
回答by Gagan Raghunath
- Go to File -> Invalidate Caches/Restart.
- Close the project.
- Go to project folder and delete .idea folder.
- Delete YourProjectName.iml in project folder.
- Delete app.iml in app folder.
- Open Android studio -> open existing project, and then select your project.
- The Load Settings error and Unsupported modules detected error will be gone.
- 转到文件 -> 使缓存无效/重新启动。
- 关闭项目。
- 转到项目文件夹并删除 .idea 文件夹。
- 删除项目文件夹中的 YourProjectName.iml。
- 删除 app 文件夹中的 app.iml。
- 打开 Android studio -> 打开现有项目,然后选择您的项目。
- 加载设置错误和检测到不支持的模块错误将消失。
回答by Shubham Singh
None of above worked for me but tried something random and it worked.
以上都不适合我,但尝试了一些随机的方法并且它起作用了。
- Copy the corrupted project directory.
- Paste it at somewhere else.
- Import it in Android Studio. (File-> New-> Import project)
- And uncorrupted project get restored.
- 复制损坏的项目目录。
- 将其粘贴到其他地方。
- 在 Android Studio 中导入它。(文件-> 新建-> 导入项目)
- 并且未损坏的项目得到恢复。
PS: You must have original corrupted project. (Means, copy it without tampering project structure)
PS:您必须有原始损坏的项目。(意思是,在不篡改项目结构的情况下复制它)