Reputation: 9545
I am not getting C++ code complete to work in Android Studio 2.1.2. I imported an existing aosp project with custom c++ and java modules. Android Studio can code complete the java code but not the c++.
I see the following error on top of the C++ file: "The file has been added after the last project sync with Gradle. Please sync the project again for the NDK support to work properly." "The project 'XXXX' is not a Gradle-based project."
I tried importing the project 2 different ways with no luck: 1. Generate an *.isr file and opened that. Pointed to NDK home. Then "Invalidate Caches/Restart" 2. from "Welcome to android Studio" a. Import project(Eclipse, Gradle, etc.) b. Select project to import c. Import project from external model "Gradle" d. Point Gradle home: "/opt/android-studio/gradle/gradle-2.10"
Any ideas?
Upvotes: 1
Views: 421
Reputation: 356
To compile c/c++ files in Android Studio you should use NDK and then make calls from java to your native code using JNI.
Drop your native files into src/main/jni/ folder.
And then configure gradle. Something like:
android {
ndk {
moduleName "mylibrary"
ldLibs "m", "log", "android"
} }
You would need to download and config ndk.
There are a lot sources how to do it, google "how to use c++ file in android studio". Top link from search
Or you could compile your c code not in Android Studio as .so library with proper JNI signatures(using javah) and drop it in JNIlibs folder.
Upvotes: 1