aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Adam Michael <ajmichael@google.com>2016-12-21 23:06:37 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-12-22 09:57:15 +0000
commitaa4ca94d7b44e6a776e46ed50d9b245058e8b9de (patch)
tree3263d14610dea59ac9fc8b1b5e7264b373a42615 /examples
parentac007764cbb2fb30ce6458a357fb0988d08bbfd3 (diff)
Update the Bazel sample app to demonstrate the support library syntax.
Also removes some outdated comments in the README.md. -- PiperOrigin-RevId: 142705870 MOS_MIGRATED_REVID=142705870
Diffstat (limited to 'examples')
-rw-r--r--examples/android/README.md30
-rw-r--r--examples/android/java/bazel/AndroidManifest.xml3
-rw-r--r--examples/android/java/bazel/BUILD3
-rw-r--r--examples/android/java/bazel/MainActivity.java4
-rw-r--r--examples/android/java/bazel/res/values/colors.xml4
-rw-r--r--examples/android/java/bazel/res/values/styles.xml6
6 files changed, 30 insertions, 20 deletions
diff --git a/examples/android/README.md b/examples/android/README.md
index 36f3345b68..b3c035bb26 100644
--- a/examples/android/README.md
+++ b/examples/android/README.md
@@ -5,22 +5,20 @@ android_sdk_repository(
name="androidsdk",
path="<full path to your Android SDK>",
api_level=<api level>,
- build_tools_version="<build tools version>")
+)
android_ndk_repository(
name="androidndk",
path="<path to your Android NDK>",
- api_level=<api_level>)
+ api_level=<api_level>,
+)
```
-For the `android_sdk_repository` rule, the values of the `api_level` and
-`build_tools_version` attributes correspond, respectively, to directories
-containing specific versions of the `android.jar` file and build tools. For
-example, if `path=/Users/xyzzy/Library/Android/sdk`,
-`api_level=21`, and `build_tools_version="21.1.1"` (note that
-quotes are required in the second case), then your SDK must contain the
-directories
-`/Users/xyzzy/Library/Android/sdk/platforms/android-21` and
-`/Users/xyzzy/Library/Android/sdk/build-tools/21.1.1`.
+
+For the `android_sdk_repository` rule, the value of `api_level` corresponds to
+a directory in the SDK containing the specific version of `android.jar` to
+compile against. For example, if `path = "/Users/xyzzy/Library/Android/sdk"` and
+`api_level = 21`, then the directory
+`/Users/xyzzy/Library/Android/sdk/platforms/android-21` must exist.
Similarly, for the `android_ndk_repository` rule, the value of the `api_level`
attribute corresponds to a directory containing the NDK libraries for that
@@ -29,17 +27,17 @@ API level. For example, if
`api_level=21`, then you your NDK must contain the directory
`/Users/xyzzy/Library/Android/android-ndk-r10e/platforms/android-21`.
+The example `android_binary` depends on
+`@androidsdk//com.android.support:appcompat-v7-25.0.0`, so you will need to
+install the Google Support Libraries version 25.0.0 from the Android SDK
+Manager.
+
The following command can be used to build the example app:
```
bazel build //examples/android/java/bazel:hello_world
```
-Yes, we know that this is a little clunky. We are working on the following things (and more):
-
- * Supporting other architectures than `armeabi-v7a` and compilers other than GCC 4.9
- * Eliminating the big ugly deprecation message from the console output of Bazel
-
We also have a nice way to speed up the edit-compile-install development cycle for physical Android devices and emulators: Bazel knows what code changed since the last build, and can use this knowledge to install only the changed code to the device. This currently works with L devices and changes to Java code and Android resources. To try this out, take an `android_binary` rule and:
* Set the `proguard_specs` attribute to `[]` (the empty list) or just omit it altogether
diff --git a/examples/android/java/bazel/AndroidManifest.xml b/examples/android/java/bazel/AndroidManifest.xml
index 3ad459c90b..760a6fbf8c 100644
--- a/examples/android/java/bazel/AndroidManifest.xml
+++ b/examples/android/java/bazel/AndroidManifest.xml
@@ -8,7 +8,8 @@
android:targetSdkVersion="21" />
<application
- android:label="Bazel App" >
+ android:label="Bazel App"
+ android:theme="@style/MyTheme" >
<activity
android:name="bazel.MainActivity"
android:label="Bazel" >
diff --git a/examples/android/java/bazel/BUILD b/examples/android/java/bazel/BUILD
index ad550b5494..3c56858396 100644
--- a/examples/android/java/bazel/BUILD
+++ b/examples/android/java/bazel/BUILD
@@ -15,11 +15,12 @@ android_binary(
"MainActivity.java",
"Jni.java",
]),
- legacy_native_support = 0,
manifest = "AndroidManifest.xml",
+ resource_files = glob(["res/**"]),
deps = [
":jni",
":lib",
+ "@androidsdk//com.android.support:appcompat-v7-25.0.0",
],
)
diff --git a/examples/android/java/bazel/MainActivity.java b/examples/android/java/bazel/MainActivity.java
index 4fdecd708f..c55815adce 100644
--- a/examples/android/java/bazel/MainActivity.java
+++ b/examples/android/java/bazel/MainActivity.java
@@ -1,13 +1,13 @@
package bazel;
-import android.app.Activity;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
import android.util.Log;
/**
* Main class for the Bazel Android "Hello, World" app.
*/
-public class MainActivity extends Activity {
+public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/examples/android/java/bazel/res/values/colors.xml b/examples/android/java/bazel/res/values/colors.xml
new file mode 100644
index 0000000000..521c64473a
--- /dev/null
+++ b/examples/android/java/bazel/res/values/colors.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <item name="primary" type="color">#FF99CC00</item>
+</resources>
diff --git a/examples/android/java/bazel/res/values/styles.xml b/examples/android/java/bazel/res/values/styles.xml
new file mode 100644
index 0000000000..db98a7490d
--- /dev/null
+++ b/examples/android/java/bazel/res/values/styles.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="MyTheme" parent="Theme.AppCompat">
+ <item name="colorPrimary">@color/primary</item>
+ </style>
+</resources>