Android Studio-项目中的所有文件名都是红色的,但是没有错误

我在 Android Studio 中导入了一个 ADT 项目。我有很多错误,但我可以全部修正。我不认为“如何”在这种情况下是重要的,我不能回忆所有的错误反正。该项目现在运行没有错误,但不知何故 Android 工作室标记所有文件红色。只有文件名,代码中没有错误。我试过清理和重启。

enter image description here

以前有人经历过类似的事情吗? 或者也许有人可以解决与 IntelliJ 相关的问题?

编辑:
是版本控制。该项目没有版本控制,但在 SVN 控制的文件夹中。红色就是这个意思。解决方案可以是将项目复制到其他文件夹或将文件添加到版本控制中。

92000 次浏览

Perhaps you are seeing the File Status colors that Android Studio uses to show the status of the file. Open Settings and go to Editor > Colors & Fonts > File Status. Here you can see what all of the different colors mean. My guess is that your reddish files are that color because you have not yet added them to source control.

If anyone happens to import a project and then all files and folder names are brown, that means files/folders are unknown. This happens if imported project has VCS control, to solve this you just have to check in your project root folder for .idea folder and inside it if there's an XML file called vcs.xml: if so, just rename it or delete it, then close and reopen project, all names will become black.

I had the same problem: everything was in red and my MainActivity was not found. I resolved it doing:

File -> Invalidate Caches / Restart

From the screenshot that you have attached, it appears that it is because of VCS enabled.

Case 1: You want to use VCS. And you have not committed the code. If this is the case, then please commit the code.

Case 2: VCS is enabled and you are not aware of that. To disable this, Go to Setting-> Version Control.

In the right panel, you will see a Project and type of VCS. Select that row and click on the VCS item. In the dropdown, select .

This will resolve your issue.

It can be because of you version control system. May be you haven't committed your change on the files committing your change will restore the file names' color to white or go to File->Settings->Version Control and disable the VCS

Using SVN repository under Android Studio, I got same issue after renaming the package name. To solve it, you will need to do a right click on the red files/Subversion/Add to CVS -> Then the files will be green, after you have to commit them, they will be normal (black color).

I've had similar problems with IntelliJ and have some more details that may prove helpful:

  • If for some reason IntelliJ imports a project using a VCS other than what is used by your project, it may effect how it looks at project roots. For example, IntelliJ kept importing projects with Subversion as the VCS when we use Git -- Subversion creates a root for every top-level folder and Git just had just a single root (I have no idea why).
  • As suggested above, going into Settings->Version Control (IntelliJ IDEA ->Preferences for OS X) and changing the VCS type to "Git" or "none" would make the red characters go away.
  • I had no idea why IntelliJ kept importing the project as Subversion so I went into the plugins and disabled "Subversion Integration" -- that got rid of the problem for good.

This happened to me every time I would set up a git repo in my project. To answer the question, simply add the problematic files to your VCS, "git add" in my case and you should be good to go.

It is because Version Control(like Git) have been enable in your project.

Go to File -> Settings -> Editor. Under Version Control select File Status Colors. It contains list of different colors and what they mean.

enter image description here

Solutions for existing project that are newly cloned

  • delete or rename .idea/vcs.xml and restart android studio
  • Check exact folder is added as root in File->Settings->Version Control
  • Check proper vcs tool configured in File->Settings->Version Control and remove unwanted entries

I went to my project folder (c:\users\ ... \AndroidStudioProjects\my project folder\ , and deleted the .git folder. (it's hidden).

The Problem Solved.

VCS: commit After that, the red color is gone in my case.

Just right-click on the file -> GIT -> Add.

I had similar issue, i had git version control installed and it happened after i changed my package name.

I had resolved the same by "git add .".

Hope it helps others.

Well the same thing happened to me but I was sure there were no errors, nothing was wrong and the answer to this red is probably because you are using git and android studio tells you that you need to update (git add files), I hope it works for you.