"This file is not part of the project Please include it in the appropiate build file(build.gradle, CMakeLists.txt....)

Viewed 1365

I am new to Android Studio and couldn't solve this problem. I wrote a cpp code with it's header file, but even though I added the cpp file to CMakeLists.txt, I still get this error.

How can I include my cpp file to a build file?

1 Answers

Fixed this issue by:

Step1: First make sure you added the CMakeLists.txt inside "app" folder.

Step2: Check the below image. Choose the option "Link C++ Project with Gradle" with your cpp file.

enter image description here

Step3: A new window gets opened. Just add the path there for CMakeLists.txt.

In build.gradle below entry get created automatically:

externalNativeBuild {
        cmake {
            path file('CMakeLists.txt')
        }
    }

Step4: Go to File and choose option "Invalidate Caches / Restart..."

After Android Studio get restarted, this issue gets fixed.

Related