为什么 Android Studio 在项目移动后使用旧的源位置?
我有一个基于 Kotlin 的 Android Studio 项目,位于 C:\DEV\PROJECT1 ,工作正常。我将项目 SOURCE 复制到 C:\DEV\PROJECT2 并将其加载到 Android Studio 中。
我的所有类以及命名空间在左侧的“项目”面板和每个编辑器选项卡中的名称下都有红色下划线。 IDE 认为存在重复的类,因为它仍然引用 OLD 目录中的源代码。
当我调试时,IDE 会提示某个类有多个版本,并且在编辑器窗口的顶部,您可以从任一目录中进行选择。
由于多种原因,这给我带来了一个巨大的问题,所以我想让 IDE 在加载项目的新副本时忘记旧目录。
我已经尝试了在互联网上找到的所有技巧,但没有一个起作用。我已手动删除了 C:\Users\me\AppData\Local\Google 中的“缓存”目录...我已在 IDE 中使用“文件”->“无效缓存”执行了相同的操作。我已手动删除 .gradle 和 .idea 目录以及所有构建目录。
我有一个朋友在他的计算机上加载了项目 SOURCE,就像我上面所做的那样,他也遇到了同样的问题。所以我不认为这是环境问题。
有谁知道这里发生了什么以及如何解决它?
谢谢。
I have a Kotlin-based Android Studio project located at C:\DEV\PROJECT1 which works fine. I copied the project SOURCE to C:\DEV\PROJECT2 and loaded it into Android Studio.
All of my classes as well as my namespace have a red underline under their names in the Project panel to the left and each editor tab. The IDE thinks there are duplicate classes because it's still referencing the source code in the OLD directory.
When I debug, the IDE says there are multiple versions of a class and at the top of the editor window you can choose from either directory.
This is causing a huge problem for me for multiple reasons, so I'd like to get the IDE to forget about the old directory when loading the new copy of the project.
I've tried all the tricks I found on the Internet but none of them work. I've manually deleted the "caches" directory in C:\Users\me\AppData\Local\Google... I've done the same thing within the IDE with File->Invalidate Caches. I've manually deleted the .gradle and .idea directories, as well as all build directories.
I had a friend load the project SOURCE on his computer the same as I've done above, and he experiences the same issue. So I don't believe it's an environment issue.
Does anyone know what's going on here and how to fix it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提到的其他答案都不适合我。我要做的就是更改 settings.gradle 中“rootProject.name”的值。在我这样做之前,它会始终记住项目曾经所在的旧目录,并且始终使用该目录中的源代码。
这对我来说毫无意义,所以我要发布另一个问题,看看是否有人可以解释为什么 Android Studio 永远不会忘记项目名称的位置。我无法想象有人会想要这种行为。
None of the other answers mentioned worked for me. What I had to do was change the value of 'rootProject.name' in settings.gradle. Until I did this, it would always remember the old directory where the project used to be and would always use source from that directory.
This makes no sense to me so I'm going bo post another question to see if someone can explain why Android Studio NEVER forgets the location of a project name. I can't imagine anyone ever wanting that behavior.