Use rules_android in Android tutorial
This change updates [Bazel Android Tutorial](https://docs.bazel.build/versions/master/tutorial/android-app.html) to use [rules_android](https://github.com/bazelbuild/rules_android) so that users aren't exposed to the deprecated native rules and are better prepared for the future use of [rules_android](https://github.com/bazelbuild/rules_android).
Caveat: I had to use commit instead of a tag for [rules_android](https://github.com/bazelbuild/rules_android) since it hasn't been released in a while even though it gets changed.
Closes #9220.
PiperOrigin-RevId: 264900814
diff --git a/site/docs/tutorial/android-app.md b/site/docs/tutorial/android-app.md
index 90112ff..3013c11 100644
--- a/site/docs/tutorial/android-app.md
+++ b/site/docs/tutorial/android-app.md
@@ -105,16 +105,38 @@
ERROR: The 'info' command is only supported from within a workspace.
```
-## Integrate with the Android SDK
+## Integrate with the Bazel Android Rules
+
+Android-specific Bazel rules are defined in a separate repository: https://github.com/bazelbuild/rules_android
+
+Add the following lines to your `WORKSPACE` file:
+
+```python
+RULES_ANDROID_VERSION = "b60d84e5635233d2d8fc905041576bd44cefbb94"
+RULES_ANDROID_SHA = "d7cdd6e6aced08e152ff14074ea6cde98d6329d7fe1c5cd578a1e4edb4b3e4c9"
+
+http_archive(
+ name = "rules_android",
+ urls = [
+ "https://github.com/bazelbuild/rules_android/archive/%s.zip" % RULES_ANDROID_VERSION,
+ ],
+ strip_prefix = "rules_android-%s" % RULES_ANDROID_VERSION,
+ sha256 = RULES_ANDROID_SHA,
+)
+```
+
+This will allow you load Android rules required for the build.
Bazel needs to run the Android SDK [build
tools](https://developer.android.com/tools/revisions/build-tools.html) to build
the app. This means that you need to add some information to your `WORKSPACE`
file so that Bazel knows where to find them.
-Add the following line to your `WORKSPACE` file:
+Add the following lines to your `WORKSPACE` file:
```python
+load("@rules_android//android:rules.bzl", "android_sdk_repository")
+
android_sdk_repository(name = "androidsdk")
```
@@ -238,6 +260,8 @@
`src/main/java/com/example/bazel/BUILD`:
```python
+load("@rules_android//android:rules.bzl", "android_library")
+
package(
default_visibility = ["//src:__subpackages__"],
)
@@ -269,6 +293,8 @@
`src/main/BUILD`:
```python
+load("@rules_android//android:rules.bzl", "android_binary")
+
android_binary(
name = "app",
manifest = "AndroidManifest.xml",
@@ -381,7 +407,7 @@
for the app and a `WORKSPACE` file that identifies the top level of the
workspace directory.
* Updated the `WORKSPACE` file to contain references to the required
- external dependencies, like the Android SDK.
+ external dependencies, like the Bazel Android rules and Android SDK.
* Created a `BUILD` file.
* Built the app with Bazel.
* Deployed and ran the app on an Android emulator or physical device.