grpc/examples/android/binder/java/io/grpc/binder/cpp
Ming-Chuan d6bb391449 [Build] Migrate Android NDK, android rules and platforms (#36116)
This commit does the following 3 things for Android bazel rules, which depends on each other

1. Update NDK to 26.2.11394342 (and a few other Android things)
2. Use rules_android_ndk instead of builtin `native.android_ndk_repository`
    * `third_party/android/android_configure.bzl` was a workaround for users who don't set `$ANDROID_NDK_HOME` env var. Now with rules_android_ndk, we can declare repo without registering the toolchain. Instead users who need NDK toolchain should use `--extra_toolchains` to manually register the toolchain, as shown in README.md.
3. Migrate to platforms. See https://bazel.build/concepts/platforms
    * Currently we declares android platforms that is needed for binder transport APK. Later gRPC repo can gradually migrate to platforms for other platforms.
    * The value of `crosstool_top` will still be `//external:android/crosstool` (which is the default value), so existings android `config_settings` will still work. We should migrate them to match with `@platforms//os:android` constraint later.

The platforms migration needs Bazel 7.0 to work so we also override bazel version in testing scripts.

Closes #36116

PiperOrigin-RevId: 617244655
2024-03-19 11:46:15 -07:00
..
exampleclient [Build] Migrate Android NDK, android rules and platforms (#36116) 2024-03-19 11:46:15 -07:00
exampleserver [Build] Migrate Android NDK, android rules and platforms (#36116) 2024-03-19 11:46:15 -07:00
README.md [Build] Migrate Android NDK, android rules and platforms (#36116) 2024-03-19 11:46:15 -07:00

README.md

gRPC-core BinderTransport example apps

Build Instruction

  1. Install Android SDK and NDK. Only NDK version >= 25 is supported. We tested against SDK Platform 33 and NDK 26.2.11394342.
  2. Make sure Bazel is at least 7.0. Use export OVERRIDE_BAZEL_VERSION=7.1.0 to selected a supported version listed in bazel/supported_versions.txt if necessary.
  3. Point environment variables to install locations of SDK and NDK
    export ANDROID_HOME=$HOME/android-sdk
    export ANDROID_NDK_HOME=$HOME/android-sdk/ndk/26.2.11394342
    
  4. To build a fat APK that supports x86_64, armv7, and arm64:
    bazel build \
      --extra_toolchains=@androidndk//:all \
      --android_platforms=//:android_x86_64,//:android_armv7,//:android_arm64 \
      --copt=-Wno-unknown-warning-option \
      //examples/android/binder/java/io/grpc/binder/cpp/exampleserver:app \
      //examples/android/binder/java/io/grpc/binder/cpp/exampleclient:app
    
  5. adb install bazel-bin/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/app.apk
  6. adb install bazel-bin/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/app.apk