rob42
02/23/2024, 8:26 PMandroid { externalNativeBuild { ... } }
to build a C shared library using the Android NDK toolchain + cmake.
Does anyone have any advice for how to approach this for compose desktop, since externalNativeBuild
is part of the android gradle plugin, and therefore can't be used for compose desktop?Dima Avdeev
02/25/2024, 8:38 AMrob42
02/26/2024, 9:35 PMjw
02/26/2024, 11:44 PMHenri Gourvest
02/27/2024, 12:00 AMcompose.desktop {
application {
mainClass = "MainKt"
jvmArgs("-Djava.library.path=libs/jni")
...
}
}
tasks.register("compileCPP") {
exec {
workingDir("native")
inputs.dir(workingDir)
val libName = System.mapLibraryName("native")
outputs.file("$projectDir/libs/jni/$libName")
val arch = System.getProperty("os.arch")
val os = System.getProperty("os.name")
val buildPath = "${layout.buildDirectory.get()}/cmake/$arch/$os"
commandLine("cmake", "-DCMAKE_BUILD_TYPE=Release", "CMakeLists.txt", "-B", buildPath)
doLast {
exec {
commandLine("cmake", "--build", buildPath)
}
copy {
from("$buildPath/$libName")
into("$projectDir/libs/jni")
}
}
outputs.upToDateWhen { true }
}
}
tasks.getByPath("desktopProcessResources").dependsOn("compileCPP")
Dima Avdeev
02/27/2024, 11:11 AMHenri Gourvest
02/28/2024, 10:37 AMjw
02/28/2024, 11:30 AMHenri Gourvest
02/28/2024, 3:04 PMjw
02/28/2024, 3:06 PMjw
02/28/2024, 3:07 PMHenri Gourvest
02/28/2024, 3:10 PMjw
02/28/2024, 3:11 PMjw
02/28/2024, 3:12 PMjw
02/28/2024, 3:13 PMjw
02/28/2024, 3:14 PMHenri Gourvest
02/28/2024, 3:19 PMHenri Gourvest
02/28/2024, 3:34 PMrob42
02/28/2024, 6:01 PMhttps://github.com/cashapp/zipline/blob/trunk/zipline/build.gradle.ktsThis looks like a treasure trove, but I don't see the manual cmake invocation for jvm?
jw
02/28/2024, 6:02 PMrob42
02/28/2024, 6:02 PMrob42
02/28/2024, 6:03 PMrob42
02/28/2024, 6:03 PMjw
02/28/2024, 6:03 PM.github/workflows/build_mac.sh
once and basically be done with it for local devjw
02/28/2024, 6:04 PMrob42
02/28/2024, 6:15 PMHenri Gourvest
02/28/2024, 10:19 PMcmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=toolchain-Linux-aarch64.cmake -DCMAKE_BUILD_TYPE=Release CMakeLists.txt -B './build/Linux/aarch64'
cmake --build './build/Linux/aarch64'
toolchain-Linux-aarch64.cmake
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_C_COMPILER "zig" cc -target aarch64-linux-gnu)
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-linux-gnu)
I'm on Linux and I can compile for different architectures for Linux and Darwin. Unfortunately, to cross compile for Windows I encounter many errors with mingw. As an alternative, I use "mingw64-cmake" instead of cmake and it works very well.rob42
02/29/2024, 6:48 PMrob42
02/29/2024, 6:53 PMset(JAVA_INCLUDE_PATH "${CMAKE_CURRENT_LIST_DIR}/../include")
set(JAVA_INCLUDE_PATH2 "${JAVA_INCLUDE_PATH}/unix")
and then in my CMakeLists.txt
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
find_package(JNI REQUIRED)
which then gives me a JNI::JNI target I can use with target_link_libraries
I haven't tested Android yet, but it should "just work" to, because find_package(JNI) is meant to be supported by the ndk toolchain too.rob42
02/29/2024, 6:54 PMjw
02/29/2024, 6:55 PMrob42
02/29/2024, 6:59 PMHenri Gourvest
03/01/2024, 3:22 PMrob42
03/01/2024, 4:38 PMHenri Gourvest
03/01/2024, 4:50 PM