From 3d6789cb7065b3e10a0ed6ed42d2a9943e26ab58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Cig=C3=A1nek?= Date: Tue, 23 Jan 2024 16:48:42 +0100 Subject: [PATCH] bindings/kotlin: Fix native lib not found error in example app on x86_64 Closes #160 --- bindings/kotlin/.gitignore | 1 + bindings/kotlin/lib/build.gradle | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bindings/kotlin/.gitignore b/bindings/kotlin/.gitignore index 872d8e935..075339fa1 100644 --- a/bindings/kotlin/.gitignore +++ b/bindings/kotlin/.gitignore @@ -4,4 +4,5 @@ # Ignore Gradle build output directory build +local.properties *.hprof diff --git a/bindings/kotlin/lib/build.gradle b/bindings/kotlin/lib/build.gradle index 463b007d5..8213c87a6 100644 --- a/bindings/kotlin/lib/build.gradle +++ b/bindings/kotlin/lib/build.gradle @@ -7,6 +7,7 @@ plugins { android { compileSdkVersion 33 + ndkVersion '25.2.9519653' namespace 'org.equalitie.ouisync' @@ -64,10 +65,29 @@ dependencies { cargo { module = "$rootDir/../.." libname = 'ouisync_ffi' + + // Targets can be overriden with "rust.targets" in local.properties. + // Example: "rust.targets=arm64,x86_64". + // More info: https://github.com/mozilla/rust-android-gradle. targets = ['arm', 'arm64', /* 'x86', */ 'x86_64'] + profile = 'release' extraCargoBuildArguments = ['--package', 'ouisync-ffi'] + + // HACK: Recent NDK (since r23) no longer links `libgcc`, which breaks some libraries since + // they depended on the symbols from `libclang_rt.builtins-x86_64-android` + // (e.g. `__extenddftf2`, ...). To work around it, we link the library explicitly by setting + // it through the RUSTFLAGS env variable. + // More info: https://github.com/bbqsrc/cargo-ndk/issues/94. + exec { spec, toolchain -> + if (toolchain.target == 'x86_64-linux-android') { + def clangVersion = '14.0.7' + def libDir = "${android.sdkDirectory}/ndk/${android.ndkVersion}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${clangVersion}/lib/linux" + + spec.environment('RUSTFLAGS', "-L${libDir} -lstatic=clang_rt.builtins-x86_64-android") + } + } } tasks.register('generateBindings', Exec) {