Android Studio Error Communicating With System CMake - android-studio

I just created a trivial Android project with C++ support using Android Studio 3.0.1 on OS X High Sierra and I'm trying to figure out how to get CMake support.
I wasn't able to install CMake through Android Studio because there's an error with the project and the Tools > Android option is not available through the menu.
Here's what the project looks like:
For comparison, here's another trivial project without C++ support showing the Tools > Android option.
I read something about configuring Android Studio to use the system cmake. Apparently, you can override the cmake.dir setting in the project's local.properties file:
https://developer.android.com/studio/projects/add-native-code.html
excerpt:
Include the path to the CMake installation in your project's
local.properties file: cmake.dir="path-to-cmake"
So, I set the cmake.dir to /usr/local (because I already installed cmake previously through homebrew and changed the properties file)
It now reads (replacing ~ with your home directory)
# ... some comments warning you not to modify
# the properties file ...
ndk.dir=~/Library/Android/sdk/ndk-bundle
sdk.dir=~/Library/Android/sdk
cmake.dir="/usr/local"
Android Studio now shows the error message (newlines and \s inserted for legibility and home directory replaced with ~):
Error:Error occurred while communicating with CMake server.
Check log
~/AndroidStudioProjects/Cpptest/
\ app/.externalNativeBuild/cmake/
\ debug/armeabi-v7a/cmake_server_log.txt
for additional information.
However, the contents of that file suggest that the cmake binary did something reasonable in response to a command invoked by Android Studio.
CMAKE SERVER:-
CMAKE SERVER: [== "CMake Server" ==[
CMAKE SERVER: {"supportedProtocolVersions":[{"isExperimental":true,"major":1,"minor":1}],"type":"hello"}
CMAKE SERVER: ]== "CMake Server" ==]
The system CMake is version 3.10.0 which is greater than 3.7 (I believe the minimum supported version).
How do I "convince" Android Studio to use the system CMake?
Is there a way to install a CMake distribution managed by the IDE if Tools > Android is not available?
If neither of those options seems straightforward, can I configure Android Studio to use a different build system for the C++ sources, like GNU Make or just plain gradle?

So, I still don't know why pointing Android Studio at the system CMake didn't work. I also tried installing a "full CMake" distribution through their website (https://cmake.org/download/) and pointing to /Applications/CMake.app/Contents/
However, it is possible to install CMake and lldb in a different way in Android Studio on OS X even if Tools > Android Does not appear.
And that is:
Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools
Or, equivalently, Cmd , and then type sdk in the search field and then click the SDK Tools tab.
Here's a picture.

There was an issue in earlier versions of external CMake support where we didn't support future CMake server protocol versions. This has since been fixed. If you try a recent Android Studio 3.1 I think it should work.

Related

Android Studio C++ Support Missing

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.

which cmake will Android plugin use?

With Android Studio 3.3 I use native (C++) library, which I built with CMake. The Android plugin (v. 3.2.1) will choose the 'builtin' or 'external' cmake, depending on the configuration of externalNativeBuild, as documented at developer.android.com.
I want to add an extra custom task (install) that should use the same cmake version as the Android Plugin. But even with the 'builtin' cmake, it's not clear what the path is. I can find android.sdkDirectory, but even there I have today sdk\cmake\3.6.4111459 and sdk\cmake\3.10.2.4988404, and for some strange reason, some of my projects choose 3.6, while others use 3.10. This contradicts the official the release notes for Android Studio that "Gradle still uses version 3.6.0 by default", but well…
How can I decide which to use, without reimplementing the Android Plugin's obscure logic?
One workaround that may help, parse the first line of the generated file .externalNativeBuild/cmake/debug/armeabi-v7a/cmake_build_command.txt:
Executable : C:\local\Android\sdk\cmake\3.10.2.4988404\bin\cmake.exe
This still needs some adjustments, because the later versions of build tools will use .cxx instead of .externalNativeBuild; the build variant names may be different too.
Android Studio will pick up the latest CMake version under sdk\cmake, but you can configure your particular version from
externalNativeBuild {
cmake {
...
version "cmake-version"
}
}
And specify our custom CMake director as below inside local.properties
cmake.dir="path-to-cmake"
Or, you can choose NOT to upgrade your CMake from SDK Manager (just to delete the sdk\cmake\<version to delete> folder will be fine) so that you can stick to the CMake version your project is comfortable with.

Android Studio SDK manager doesn't show the candidate packages(How to install CMake)

From the post "Add C and C++ Code to Your Project",
You can install these components using the SDK Manager:
From an open project, select Tools > Android > SDK Manager
from the menu bar. Click the SDK Tools tab. Check the boxes next to LLDB,
CMake, and NDK, as shown in figure 1.
there is a image shows
But my Android Studio is not like that.
I upload a image to show my Android Studio sdk manager settings:
I googled for a while, but I didn't find anything useful. My PC is win10 64bit, I run Android Stdio 64bit, version is 2.2, I use the Android Studio bunndle version(I assume the AS and the sdk are one thing).
I also run Android Studio 2.3 on another PC, I check the sdk manager on version 2.3, it looks like behaving the same. I also try to run AS in the administrator role. it looks like behaving the same too.
The different on the AS2.2 and AS2.3 is that I can run the sdkmanager command in a win shell to install the CMake/LLDB on the PC that has AS 2.3, but I can't find the sdkmanager command in the SDK folder which is associated with the AS 2.2, so I go to download a standlone command line tools from the developer.android.com, I unzip the downloaded file and get a fold named "tool", what should I do? shold I merge the downloaded tool folder into the android_sdk/tools?
The below image is the sdk settings on another PC that has installed the AS 2.3. I installed the CMake the LLDB from the command line: "sdkmanager.bat cmake;3.6.4111459"
Why my Android Studio doesn't show the candidate not
installed packages?
Shold I merge the downloaded command line tool folder into the android_sdk/tools?

Can Android Studio use the system CMake?

I'm using Android Studio + CMake to build a native library. AS requested installing CMake, even though I already have CMake installed and in my path. Can you tell AS to look for CMake at a certain location, instead of installing another CMake?
The new Android plugin for gradle 3.0 will support using system CMake, for CMake 3.7+.
From that webpage:
Download and install CMake 3.7 or higher from the official CMake website.
Include the path to the CMake installation in your project's local.properties file:
cmake.dir="path-to-cmake"

Open cocos2d-x-3.7 in Android Studio

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.

Resources