Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
In this quick guide, we are going to use Bazel to build multiple applications which share a native library. We will be targeting 4 platforms: iOS, macOS, Android and Web. In the end you should have a solid basement to build your first cross-platform application (or move an existing project to Bazel). I listed the project on Github - I encourage you to clone it and experiment.
Android NDK 21. NDK v21 is currently the latest supported version
git_repository( name = "build_bazel_rules_apple", remote = "https://github.com/bazelbuild/rules_apple.git", tag = "1.1.3", ) git_repository( name = "build_bazel_rules_swift", remote = "https://github.com/bazelbuild/rules_swift.git", tag = "1.2.0", ) load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies") swift_rules_dependencies()
git_repository( name = "build_bazel_rules_apple", remote = "https://github.com/bazelbuild/rules_apple.git", tag = "1.1.3", ) git_repository( name = "build_bazel_rules_swift", remote = "https://github.com/bazelbuild/rules_swift.git", tag = "1.2.0", ) load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies") swift_rules_dependencies()
git_repository( name = "build_bazel_rules_android", remote = "https://github.com/bazelbuild/rules_android.git", tag = "v0.1.1", ) android_sdk_repository( name = "androidsdk", path = "", ) android_ndk_repository( name = "androidndk", api_level = 21, path = "", )
These attributes are not listed in any Bazel tutorial I found! If you omit those, linker will simply drop the symbols, making the library empty. This was raised to Bazel community and eventually should be fixed in a new rule.
git_repository( name = "rules_jvm_external", remote = "https://github.com/bazelbuild/rules_jvm_external.git", tag = "4.2", ) load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( artifacts = [ "androidx.appcompat:appcompat:1.3.0", "com.google.android.material:material:1.4.0", "androidx.constraintlayout:constraintlayout:2.0.4", ], repositories = [ "https://maven.google.com", ], )
git_repository( name = "emsdk", remote = "https://github.com/emscripten-core/emsdk.git", strip_prefix = "bazel", tag = "3.1.25", ) load("@emsdk//:deps.bzl", "deps") deps() load("@emsdk//:emscripten_deps.bzl", "emscripten_deps") emscripten_deps()