0

I have written a C++ library and its cmake. I'm trying to get that library ported on Android so that I can use the library there. I'm trying to generate .so files so that I can link it in JNI.

%Path to android sdk cmake%\cmake -G Ninja . ^
-GAndroid Gradle - Ninja ^
-DANDROID_ABI=armeabi-v7a ^
-DANDROID_NDK=%Path to android sdk%\Sdk\ndk-bundle ^
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=%OUTPUT% ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_MAKE_PROGRAM=%Path to android sdk ninja% ^
-DCMAKE_TOOLCHAIN_FILE=%Path to android sdk%\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake ^
-DANDROID_NATIVE_API_LEVEL=29 ^
-DANDROID_TOOLCHAIN=clang

I get the following error

CMake Error: Could not create named generator Android

On Windows, I do the following to configure it to MSVC:

cmake -G "Visual Studio 15 2017 Win64" ..

So how do I get about building the native library from the same C++ source on Windows and what would the correct CMake command be. It is fine even if it configures to android studio.

pr0py_s
  • 171
  • 9
  • Have you installed the ndk? – Alan Birtles Aug 25 '20 at 07:33
  • yes, I've Android sdk with ndk version 21.0.6113669 – pr0py_s Aug 25 '20 at 07:40
  • If your library is already CMake-based, why not just include the CMake files directly from your Android CMakeLists.txt? That will automatically build it for the right architectures with the right cross-compiler settings. – Botje Aug 25 '20 at 07:41
  • @Botje I'm using the same CMakeLists (from windows) to build it for Android – pr0py_s Aug 25 '20 at 07:52
  • 1
    Don't compile the library in advance, [integrate it into your Android app native build](https://developer.android.com/studio/projects/add-native-code#create-cmake-script) – Botje Aug 25 '20 at 08:40
  • @Botje The code is too much integrating it everytime will make my projects untidy – pr0py_s Aug 25 '20 at 08:47
  • Fine, then. Is the generator you're trying to use listed in `cmake --help`? If so, you need to surround the generator name with quotes. – Botje Aug 25 '20 at 08:49
  • yes I did put "Ninja" in quotes. But I get Could not create named generator Android – pr0py_s Aug 25 '20 at 08:55
  • 1
    Because you have two -G flags with arguments. The first one is useless , and the second one is missing quotes around "Android Gradle - Ninja". What you copy pasted was not a shell command so you need to add quotes. – Botje Aug 25 '20 at 09:32

0 Answers0