Build configuration error using Android NDK - intellij-idea

There is a build configuration error (Gradle sync failed) starting a new simple Android project using IntelliJ IDEA and the installed Android SDK (API 28) to include C++ support.
If I can remember, it worked when first installed, but now any attempt to compile and build the project using the IntelliJ GUI fail. LLDB, CMake and NDK are all installed correctly in the correct folders and the local.properties file references the location of the SDK and NDK.
All attempts to refresh linked C++ projects or clear caches (invalidate caches/restart) make no difference.
CMake_server_log.txt suggests:
CMAKE SERVER: CMake Error: CMake was unable to find a build program
corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You
probably need to select a different build tool.
Build output (edited to remove path):
Cause: executing external native build for cmake CMakeLists.txt
There appears to be a lack of configuration to complete the build or missing PATH or ENVIRONMENT variable. Should I manually try to change this or add some extra code to the build.gradle or CMakeLists.txt? There is the ninja application in the cmake bin directory.
Even importing other NDK sample projects fail (after downloading any required dependencies e.g. Gradle version).
Reinstalling LLDB, CMake and the NDK via SDK Tools do not solve the issue either.
I get the impression that I need to completely uninstall IntelliJ IDEA on Windows and remove any remaining folders/files associated with it, before reinstalling it. That would be a shame as IntelliJ IDEA works for other type of Android projects not requiring native C++ support.

Related

Ksp multiplatform redeclaration of files

I am implementing ksp processor in kotlin multiplatform targeting iOS and android applications, following documentation I'm defining multiple configuration names for KSP ie:
add("kspIosArm64", project(":test-processor"))
add("kspIosX64", project(":test-processor"))
However running those gives me file redeclaration error. Indeed files are created in separate locations:
build/generated/ksp/iosArm64/ and build/generated/ksp/iosX64/ but packages are the same.
And Im quite lost how to solve this issue, is there any way of getting this generated folder path for each generated file so that package can be modified?
I will try to partially answer your questions right now, not to make you stack and focus on making the project able to run. I assume that you are using XCode to run the project for iOS. The problem here is that (as you mentioned) all of those source sets are being generated with the same package name which is more a KSP issue (I think) that we have to wait for to be solved.
What you can do for now to run and test the project is:
Make sure to clean your build with ./gradlew clean before running the project (especially between Android and iOS runs)
I think clean can be added as a "step" before KMM framework task:
XCode Project file -> Build Phases -> Generate KMM framework -> add clean before running gradle task responsible for building framework (This can will make build time longer)
./gradlew :yourSharedModule:clean :yourSharedModuleName:embedAndSignAppleFrameworkForXcode
Selected only one architecture to be build when running the project
XCode Project -> Build Settings -> Architectures -> Build Active Architecture Only -> Yes
This solutions makes only one architecture to be build and run (it is probably a simulator in your case), issue here is you may have some problems with other architectures and will not be able to spot them easily on daily development.
Create some kind of env or a build config value to distinguish which ksp dependency to add (based on it's value) so not all of processors are added when running the project
XCode Project -> Build Phases -> Generate KMM framework -> pass it as gradle param -Parchitecture=someArchitecture
Or maybe it is even possible to do it within the build.gradle.kts file
Manually comment out some of ksp dependencies (iOS ones) so the only one against which you are building is left (remember to sync project and clean it)
I personally would try to implement the third solution, I do not know whether it is easy, but it seems to be the best one, other solutions should also work, but please consider them as a dirty walk-around.
I can provide more info or some kind of POC for that later, just let me know in the comments or somewhere else whether it is needed.

CMake version in CLion not updating

I cloned a project from my teacher, and I wanted to run it on CLion. However, I noticed an error:
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.14 or higher is required. You are running version 3.13.2
I configured a new CMake debugger in CLion, but I still keep getting the error.
I have a new version of CMake installed:
When I install a new CMake version in cygwin, CLion returns this:
Does anyone know what I am missing or doing wrong?
It sounds like you want CLion to use your newest version of CMake (instead of the bundled 3.13.2 version). To do that, you must add a new Toolchain (see here) or modify an existing one (see here):
On Windows CLion, navigate to File > Settings > Build, Execution, Deployment > Toolchains, and choose the toolchain you want to modify.
At the CMake: section, select a custom CMake installation by choosing the path to your custom CMake executable (likely a bin folder).
Click OK to save your changes.
Eventually, I solved the problem by installing a new version of CMake inside the cygwin installer. I also updated CLion, because I had the 2018 version and that version only supports CMake versions up to and including 3.13. After updating CLion to the 2019 version, it supported CMake versions up to and including 3.15. Because the CMake version 3.16 is pretty recently released. CLion automatically takes the maximum supported version, which in this case is the 3.15. The minimum version in de CMakeLists.txt was 3.14, so 3.15 worked fine.

How to build CLion based CMake Project with custom Toolchain from Command Line

I've only worked with CMake in conjunction with the CLion IDE but I'm aware that CMake projects can be built on the command line completely without the IDE with the CMake build system only.
Now I have some more complex CLion projects for which I created a custom toolchain and various profiles through the CLion menus (File -> Settings -> Build, Execution, Deployment --> Toolchain / CMake). I want to switch to building these projects through Gitlab CI without CLion. But how do I start a CMake build on the command line in on a build VM without CLion installed that uses the toolchain and profiles that I created in the CLion GUI?
The desired settings to reproduce are:
Using a custom gcc cross compiler for all profiles
Dependent on the profile:
passing various CMake variables (like -DMY_VAR=FOO) to my CMakeLists
choosing a debug or release build as build type
In CLion I have one custom toolchain with the special gcc and four profiles with different settings, all using this toolchain.
Does CLion generate a toolchain file somewhere in the background that I could just use (didn't find any so far) or do I need to write my own toolchain file and pass it to cmake?

pjsip using cmake

Has someone compiled pjsip using cmake?
The project does not have a way of using CMake to build the library itself (yet). But you can link to pjproject libs from your CMake project.
Here's a snippet from one of mine that uses pjproject as a dependency:
find_package(PKGCONFIG REQUIRED)
pkg_check_modules(PJSIP libpjproject>=1.14 REQUIRED)
include_directories(${PJSIP_INCLUDE_DIRS})
...
target_link_libraries(your_target ${PJSIP_LIBRARIES})
This requires pkg-config as well, and that pjproject.pc should be in it's default search path, or in directory in $PKG_CONFIG_PATH.
This should work on Linux and OS X.
I just made cmake-based compilation of PJSIP v2.3.
I use this compilation only on Windows platform for now, not tested on linux.
On Linux I recommend use PKG_CONFIG tool to discover PJSIP for your app.
Having peeked at their repository, the project is auto-tools/configure based. You would need to port the build system yourself. Depending on complexity, it is not that hard to accomplish. I have converted many projects to cmake. Maybe the pjsip comunity would welcome an upgrade to their build system, as I see they support multiple platforms like iphone, and windows through visual studio.
If you are using Clion IDE then it can automatically generate cmake file for pjproject. Just import it and it will open a wizard. You’ll need to specify the location of the sources, then select project files and include directories. Clion has the ability to make the cmake file from existing projects. for more help please see this link Clion Documentation

Setting up Xcode for developing Plug-ins

I've never worked in XCode before but I am designing a plugin (objective-c) for an open source radiology program called OsiriX. I can get the thing to compile and I can even get the plugin to run in OsiriX. But, I'm not sure how to run/debug it from XCode. Run/Debug is grayed out on my xcode. Is it because there's no main program?
(1) "Clean all" your projects so that there isn't detritus left around when you do this.
(2) Set Xcode to use a common build products directory (I stick mine in /tmp/ so that it periodically gets nuked). The preference is under the "Building" section.
(3) Re-build OsiriX (so that it'll be built in the shared location).
(4) Make sure the active configuration in your plug-in project has the exact same name as the configuration in OsiriX that you built in (3). (It should probably be "Debug" or "Release", depending on which you build). The configurations can be edited in the build settings editor.
(5) Build your plug-in.
(6) Add a custom executable to your plug-in project and set the path to OsiriX (Project -> New Custom Executable...).
You should now be able to build-and-run or build-and-debug your project. It will launch OsiriX from the build products directory. You might also want to set OsiriX to look for bundles in your build products directory, if it doesn't already. Or you could create a symbolic link from one of OsiriX's plug-in directories to the bundle in your build products directory.
cd /path/to/OsiriX's/bundle/directory
ln -s /path/to/build/products/YourPlugin.bundle
This is a very standard way of ocnfiguring Xcode for development of plug-ins. For example, preference pane developers will set up a custom executable for SystemPreferences.app (even in /Applications -- there is no need to point to a "debug" build of the application).
In order to debug your plugin, you have to be running Osirix in Xcode as well. Download the Osirix source code from Github and compile and run it. You'll have to add the plugin to its plugin list and then when you run in Xcode your NSLog statements from the plugin source will print out in the Xcode console screen for the main Osirix program. I believe breakpoints work as well.
My experience with Xcode is also somewhat limited, but I've found that using the latest version (6.1.1) I can debug my plugin simply by attaching to a running OsiriX process via the Debug -> Attach Process menu. This does not require you to build OsiriX from source - I'm currently using the standard (non-MD) version as downloaded from their website.
Note that you still need to restart OsiriX to pick up any changes to your plugin.