Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate CLion and Android NDK

Recently I've found CLion. I'm trying to configure it to work with Android ndk:

  1. I want it to use the ndk sources and headers.

  2. I want it to use the gcc and g++ compiler in the ndk.

  3. I want it to use my makefile and not cmake.

Couldn't achieve those three targets, hope you can help me :).

By the way I'm using android ndk r10e if it matters.

like image 500
Sawel Avatar asked May 13 '16 19:05

Sawel


1 Answers

You can set up CLion to build for android by doing the following:

  1. Install the NDK Standalone Toolchain (https://developer.android.com/ndk/guides/standalone_toolchain.html)

  2. In CLion Preference/Settings under Build, Execution, Deployment > Toolchains, add a new toolchain for ARM, set the C compiler path to $NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-clang, set the C++ compiler path to $NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-clang++, and if you're on Windows, set the MinGW path. The toolchain tab is a fairly new feature to Clion so make sure you have a recent version of Clion.

  3. Repeat step 2 for any other architectures you want to support

  4. Go to Build, Execution, Deployment > CMake. Add a new profile for ARM. Set the toolchain to the ARM toolchain and set the CMake options to

-DCMAKE_CXX_FLAGS="-fPIE -fPIC -lstdc++"

-DCMAKE_AR="$NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-ar"

-DCMAKE_RANLIB="$NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-ranlib"

If you're using a Mac you will need these too in order to tell CMake to not use the isysroot option

-DCMAKE_OSX_SYSROOT="/"

-DCMAKE_OSX_DEPLOYMENT_TARGET=""

  1. Repeat step 4 for any other architectures you want to support

When building, set the profile to your desired architecture (instead of Debug/Release).

Ideally, you could specify the entire toolchain (ar, ranlib, etc.) through CLion instead of using CMake options, but I haven't found a way to do so yet.

like image 83
Cameron Avatar answered Oct 17 '22 18:10

Cameron