Android Studio:此文件不属于项目,但项目构建成功

Jon*_*ren 8 android-studio

我有一个奇怪的问题,突然出现在android studio中。我创建了一个新的 cpp 文件,并将其包含在 Android.mk 中。然后我同步了项目。但是,android studio 仍然抱怨该文件不是项目的一部分,我需要同步,但整个项目构建成功。

同样,如果我从 Android.mk 中删除它没有抱怨的其他旧文件之一,然后重新同步然后尝试构建项目,如预期的那样构建失败,但 android studio 不会抱怨该文件不是一部分的项目了。

所以不知何故,突然间 android studio 编辑器无法正确识别哪些文件已同步并且是项目的一部分,但在编译期间一切都按预期工作。

有谁知道如何解决这个烦人的问题?我尝试过干净的项目,使缓存无效/重新启动以及在没有运气的情况下更新 android studio(AS 3.4 版)。

Sdg*_*emi 15

我使用“构建” > “刷新链接的 C++ 项目”菜单,它起作用了。

Android Studio 中的菜单预览


小智 4

I had a similar problem. Like yourself, I have tried everything.

  • Invalidate and Restart: Doesn't work
  • Manual deleting folders: .gradle .idea .ndkbuild etc. doesn't work
  • Clean, Rebuild, Link C++ Files: Doesn't work

One thing that kind of helped me was: I changed the NDK version. I compiled, then got a compilation error (didn't matter because it was the wrong version of NDK anyway), then I reverted to the original NDK. This appeared to solve the problem, however, it got back again.

My solution was to reset Android Studio to factory settings. If you are on Linux, you can start by deleting these folders:

rm -rf ~/.android

rm -rf ~/.AndroidStudio3.4
Run Code Online (Sandbox Code Playgroud)

Then you download and run your Android Studio and not import anything from anywhere.

I suspect the problem was caused by one of the plugins I've installed.

It may be a good idea to backup those two folders from time to time and reload them from there if necessary.

编辑:在添加更多 .cpp 文件后,上述解决方案似乎仍然存在我的问题。看到后,我搜索了该弹出窗口的来源。因此,“此文件不是项目的一部分...”弹出窗口是从 ndk-build 推送的。(类名称:NewCppSourceNotificationProvider - StaleCppProjectNotificationPanel)。我尝试过的方法以及到目前为止有效的方法;我使用 Android Studio 3.5 Canary13 和 NDK 版本 r19c(稳定版本)。我希望这可以帮助你。