Skip to content

Commit 0d7b2bd

Browse files
committed
Fix the Android build
It was previously unable to compile due to the newly introduced aws-lc-rs dependency in the Rust lib. It has a CMake dependency that was failing. The NDK version we were using had a bug that prevented it from choosing the right processor architecture and it also required some additional arguments passed in during the build. This change also makes aws-lc-rs optional and when building uniffi-bindgen we leave it out to avoid compiling for yet another architecture. It's unnecessary for that phase of the build.
1 parent aed55b4 commit 0d7b2bd

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

android/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ library.
7373
1. Ensure you have build tools available on your OS (XCode on Mac, `build-essential` on Linux)
7474
2. Clone https://github.com/get-convex/convex-mobile
7575
3. Install Android Studio
76-
4. Use the SDK Manager to install NDK version 27.0.11902837
76+
4. Use the SDK Manager to install NDK version 27.3.13750724
7777
1. Open android studio. Press shift-shift and search sdk manager
7878
2. In the SDK tools tab, go to "NDK".
7979
3. Check the "show package details" box to get more options
80-
4. Select NDK version 27.0.11902837
80+
4. Select NDK version 27.3.13750724
8181
5. On Mac it will be installed somewhere like `/Users/$USER/Library/Android/sdk/ndk/`
8282
6. Add the following to `~/.cargo/config.toml` (**use your NDK path**)
8383

android/convexmobile/build.gradle

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616
namespace 'dev.convex.android'
1717
compileSdk 34
1818

19-
ndkVersion = "27.0.11902837"
19+
ndkVersion = "27.3.13750724"
2020

2121
defaultConfig {
2222
minSdk 26
@@ -59,6 +59,17 @@ cargo {
5959
// Support 16KB page sizes
6060
// https://developer.android.com/guide/practices/page-sizes#other-build-systems
6161
spec.environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-Wl,-z,max-page-size=16384,-soname,lib${libname}.so")
62+
63+
// Required env vars for aws-lc-rs to compile its aws-lc dependency w/ CMake.
64+
def ndkRoot = new File(android.sdkDirectory, "ndk/${android.ndkVersion}")
65+
def osName = System.getProperty("os.name").toLowerCase(Locale.ROOT)
66+
def hostTag = osName.contains("windows") ? "windows-x86_64" :
67+
osName.contains("linux") ? "linux-x86_64" :
68+
osName.contains("mac") ? "darwin-x86_64" :
69+
"linux-x86_64" // Default
70+
def sysroot = new File(ndkRoot, "toolchains/llvm/prebuilt/${hostTag}/sysroot")
71+
spec.environment('ANDROID_NDK_ROOT', ndkRoot.absolutePath)
72+
spec.environment('BINDGEN_EXTRA_CLANG_ARGS', "--sysroot ${sysroot.absolutePath}")
6273
}
6374
}
6475

@@ -75,13 +86,14 @@ tasks.whenTaskAdded { task ->
7586

7687
tasks.register("generateUniFFIBinary", Exec) {
7788
workingDir "${project.projectDir}/../../rust"
78-
commandLine 'cargo', 'build'
89+
commandLine 'cargo'
90+
args 'build', '--bin', 'uniffi-bindgen', '--no-default-features'
7991
}
8092

8193
android.libraryVariants.all { variant ->
8294
def t = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) {
8395
workingDir "${project.projectDir}/../../rust"
84-
commandLine 'cargo', 'run', '--bin', 'uniffi-bindgen', '--', 'generate', '--library', "${project.layout.buildDirectory.asFile.get().path}/rustJniLibs/android/arm64-v8a/libconvexmobile.so", '--language', 'kotlin', '--out-dir', "${project.layout.buildDirectory.asFile.get().path}/generated/source/uniffi/${variant.name}/java"
96+
commandLine 'cargo', 'run', '--bin', 'uniffi-bindgen', '--no-default-features', '--', 'generate', '--library', "${project.layout.buildDirectory.asFile.get().path}/rustJniLibs/android/arm64-v8a/libconvexmobile.so", '--language', 'kotlin', '--out-dir', "${project.layout.buildDirectory.asFile.get().path}/generated/source/uniffi/${variant.name}/java"
8597
dependsOn 'generateUniFFIBinary'
8698
}
8799
def sourceSet = variant.sourceSets.find { it.name == variant.name }

rust/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ parking_lot = { version = "0.12.3" }
1818
async-once-cell = { version = "0.5.3" }
1919
serde_json = { version = "1.0.120" }
2020
rustls = { version = "0.23", features = ["aws-lc-rs"] }
21-
aws-lc-rs = { version = "1.14", features = ["bindgen"] }
21+
aws-lc-rs = { version = "1.14", features = ["bindgen"], optional = true }
22+
23+
[features]
24+
default = ["aws-lc-rs"]
2225

2326
[dev-dependencies]
2427
maplit = { version = "1" }

0 commit comments

Comments
 (0)