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?
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.
Related
I just installed Android Studio 3.6.3 on Windows 10 and I created a new Native C++ project. I can build and run the native project and I can debug Java code in the project.
The problems I'm having are:
I can't step into the C++ code when debugging
I can't set breakpoints in *.cpp files.
When I right click folders in the project view to add a new file, I only see options to add Java, Kotlin, and Android platform files. There aren't any options to add C++ source or header files.
When I open a C++ file Android Studio recommends installing plugins supporting *.cpp. The plugin it's recommending is for Arma 3 plugin development.
The "Attach Debugger To Process" menu only has Java as a debugger option. That list should also contain Native, Dual, and Auto.
I've made sure to install CMake and NDK (Side By Side) in the SDK Manager and I've configured the NDK in the project settings. I've tried reinstalling Android Studio 3.6.3 and I've also downloaded Android Studio 4.0 RC 1, but I have the same problems.
What steps am I missing to get C++ support in Android Studio?
Managed to get it working. Turns out just running the uninstaller wasn't enough, I had to follow the steps in this answer to completely uninstall Android Studio. I then reinstalled and everything seems to be good.
I have a developed app using PanoramaGL library from this link. But it is for Eclipse and I want it for Android Studio because the eclipse project is building successfully in Android Studio but it is not running. Please help me..
Did you include the library in your build.gradle file ?
There is no difference between Libraries in Eclipse and Android Studio. Just be aware that Android Studio uses Gradle as its build system.
dependencies {
compile files('libs/PanoramaGL_0.2-beta.jar')
...
}
What is the proper way to open cocos2d-x-3.7 in Android Studio?
I tried:
Open existing project in Android Studio project > Choose proj.android-studio directory (In another attempt, I also tried to choose the base directory MyGame)
Run
Error: couldn't find "libcocos2dcpp.so.
Moreover, it also does Classes directory in the Project.
Android Studio is only partially supported in cocos2d-x 3.7 and 3.8. With the default project you will only be able to run your app without debugging using Android Studio.
Prior to running your app in Android Studio you will have to compile using the Android Studio flag:
cocos compile -p android --android-studio
You will have to run this command after any changes to your app are made, since the default Android Studio currently doesn't compile your project.
Furthermore the default Android Studio project does not include the Classes directory.
Suggestion: Use Eclipse or Xcode to develop your cocos2d-x projects for now. Hopefully future versions of cocos2d-x will have better support for Android Studio out of the box, this is critical considering Google is dropping support for Eclipse.
When you try to run the application on Android Studio, you get the error couldn't find "libcocos2dcpp.so" because it doesn't have the NDK for building your game.
I recommend you to compile proj.android and import that, cocos2d-x 3.7 doesn't support full Android Studio yet. Do this:
cocos compile -p android
Then import your proj.android to Android Studio.
Now you can run your application but you won't able to debug it, bad news (it will just install the APK on your device or virtual device).
Hope it helps.
Error: couldn't find "libcocos2dcpp.so.
For this you need to compile android studio project first so .so files and classes folder will be generated.
Open your command line and enter the following command to compile your android studio project:
cocos compile -p android --android-studio --ap android-24 --app-abi x86
This will create required files in your proj.android-studio directory.
Now import this project into Android Studio and try to run it.
I am trying to build an Android Java app using Android Studio 1.0.1. However, my app uses some C++ code that I build using the NDK as controlled by Android.mk and Application.mk files. But Android Studio tries its own build and gets it wrong as it is not using my *.mk files. I know there have been some answers how to do this for previous versions of Android Studio but they evidently do not work for 1.0.1.
So how do I disable Android NDK builds in Android Studio 1.0.1?
Just add the sourceSets.main.jni.srcDirs = [] to 'android' section of your build.gradle. This will disable automatic call of ndk-build with auto-generated Android.mk.
And yes, this line should be added to the project-specific gradle file.
I've got a project that used to be in Eclipse. I've since moved it from there into Android Studio, though it's not using the Gradle build system yet.
I've setup my gradle files so that I can do gradlew build from the command-line and it will generate an APK for me.
My question now is how do I get Android studio to build using the gradle files that I've got setup instead of the using the "old" way?
For what it's worth, I'm on Windows 7.
Not sure how you are compiling the project with Android Studio without actually using Gradle because AFAIK Android Studio always uses Gradle under the hoods to build sources.
Anyway, if you have your Gradle config file ready you only have to import it to a new project in Android Studio (File > Import Project... and then select the build.gradle or settings.gradle)