I have a strange problem that suddenly appeared in android studio. I created a new cpp file, and included it in Android.mk. Then I synced the project. However, android studio still complains that the file is not part of the project and that I need to sync, BUT the whole project builds successfully.

Likewise, if I remove one of the other older files from Android.mk that it did not complain about, and resyncs and then tries to build the project, as expected the build fails, but android studio does NOT complain that that file is not part of the project anymore.

So somehow, suddenly the android studio editor is not able to correctly identify which files have been synced and are part of the project, but during compilation everything works as expected.

Does anyone know how to fix this annoying problem? I have tried clean project, invalidate caches/restart as well as updating android studio without luck (AS version 3.4).

1 Answers

Maximus On Best Solutions

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

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.

EDIT: It seems that my problem persisted after the above solution after adding more .cpp files. After seeing that, I searched where that popup came from. It follows that "This file is not part of project..." popup is pushed from ndk-build. (Class name: NewCppSourceNotificationProvider - StaleCppProjectNotificationPanel). What I tried, and what worked so far; I used Android Studio 3.5 Canary13 with NDK version r19c (Stable version). I hope this helps you.