Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,57 @@ tasks:
<<: *rules_flags
build_targets:
- "//java/com/basicapp:basic_app"
ubuntu2004_databinding:
name: "Databinding Basic app ubuntu"
platform: ubuntu2004
working_directory: examples/databinding
build_flags:
<<: *rules_flags
build_targets:
- "//java/com/basicapp:basic_app"
ubuntu2004_databinding_bzlmod:
name: "Databinding Basic app ubuntu bzlmod"
platform: ubuntu2004
working_directory: examples/databinding
build_flags:
<<: *rules_flags
? "--enable_bzlmod"
? "--enable_workspace=false"
build_targets:
- "//java/com/basicapp:basic_app"
macos_arm64_databinding:
name: "Databinding Basic app mac arm64"
platform: macos_arm64
working_directory: examples/databinding
build_flags:
<<: *rules_flags
build_targets:
- "//java/com/basicapp:basic_app"
macos_arm64_databinding_bzlmod:
name: "Databinding Basic app mac arm64 bzlmod"
platform: macos_arm64
working_directory: examples/databinding
build_flags:
<<: *rules_flags
? "--enable_bzlmod"
? "--enable_workspace=false"
build_targets:
- "//java/com/basicapp:basic_app"
windows_databinding_bzlmod:
name: "Databinding Basic app Windows Bzlmod"
platform: windows
working_directory: examples/databinding
build_flags:
<<: *rules_flags
? "--enable_bzlmod"
? "--enable_workspace=false"
build_targets:
- "//java/com/basicapp:basic_app"
windows_databinding:
name: "Databinding Basic app Windows"
platform: windows
working_directory: examples/databinding
build_flags:
<<: *rules_flags
build_targets:
- "//java/com/basicapp:basic_app"
10 changes: 10 additions & 0 deletions examples/databinding/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Flags needed while the Android rules are being migrated to Starlark.
common --experimental_google_legacy_api
common --experimental_enable_android_migration_apis
common --android_sdk=@androidsdk//:sdk
common:core_library_desugaring --desugar_java8_libs

# Flags to enable mobile-install v3
mobile-install --mode=skylark --mobile_install_aspect=@rules_android//mobile_install:mi.bzl --mobile_install_supported_rules=android_binary
# Required to invoke the Studio deployer jar
mobile-install --tool_java_runtime_version=17
1 change: 1 addition & 0 deletions examples/databinding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.lock
1 change: 1 addition & 0 deletions examples/databinding/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty build file to satisfy gazelle for rules_go.
27 changes: 27 additions & 0 deletions examples/databinding/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module(
name = "basicapp",
)

bazel_dep(name = "rules_java", version = "7.12.2")
bazel_dep(name = "bazel_skylib", version = "1.3.0")

bazel_dep(
name = "rules_android",
version = "0.6.0",
)

local_path_override(
module_name = "rules_android",
path = "../../",
)

remote_android_extensions = use_extension(
"@rules_android//bzlmod_extensions:android_extensions.bzl",
"remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

android_sdk_repository_extension = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension")
use_repo(android_sdk_repository_extension, "androidsdk")

register_toolchains("@androidsdk//:sdk-toolchain", "@androidsdk//:all")

8 changes: 8 additions & 0 deletions examples/databinding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To build, ensure that the `ANDROID_HOME` environment variable is set to the path
to an Android SDK, and run:

```
bazel build java/com/basicapp:basic_app
```

See the `.bazelrc` file for flags needed to build the app.
75 changes: 75 additions & 0 deletions examples/databinding/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

local_repository(
name = "rules_android",
path = "../..", # rules_android's WORKSPACE relative to this inner workspace
)
# --SNIP--: Everything below this line goes into the example WORKSPACE snippet in the release notes.

# rules_license
http_archive(
name = "rules_license",
urls = [
"https://github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz",
],
sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
)

# rules_jvm_external
RULES_JVM_EXTERNAL_TAG = "6.5"
RULES_JVM_EXTERNAL_SHA = "3a4d56357851cf5b0dae538b3f3e0612a4f58925dfb3cadb2e0c4e87d51e629e"

http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG)
)

# bazel_features
BAZEL_FEATURES_VERSION = "1.20.0"
BAZEL_FEATURES_HASH = "c2596994cf63513bd44180411a4ac3ae95d32bf59148fcb6087a4642b3ffef11"
maybe(
http_archive,
name = "bazel_features",
sha256 = BAZEL_FEATURES_HASH,
strip_prefix = "bazel_features-" + BAZEL_FEATURES_VERSION,
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v" + BAZEL_FEATURES_VERSION + "/bazel_features-v" + BAZEL_FEATURES_VERSION + ".tar.gz",
)
maybe(
http_archive,
name = "proto_bazel_features",
sha256 = BAZEL_FEATURES_HASH,
strip_prefix = "bazel_features-" + BAZEL_FEATURES_VERSION,
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v" + BAZEL_FEATURES_VERSION + "/bazel_features-v" + BAZEL_FEATURES_VERSION + ".tar.gz",
)
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

# Skylib
http_archive(
name = "bazel_skylib",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()

load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()

load("@rules_android//rules:rules.bzl", "android_sdk_repository")
android_sdk_repository(
name = "androidsdk",
)

register_toolchains(
"@rules_android//toolchains/android:android_default_toolchain",
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)

1 change: 1 addition & 0 deletions examples/databinding/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "basicapp")
22 changes: 22 additions & 0 deletions examples/databinding/java/com/basicapp/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.basicapp" >

<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="30" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.basicapp.BasicActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
17 changes: 17 additions & 0 deletions examples/databinding/java/com/basicapp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@rules_android//android:rules.bzl", "android_binary", "android_library")

android_binary(
name = "basic_app",
manifest = "AndroidManifest.xml",
deps = [":basic_lib"],
enable_data_binding = True,
)

android_library(
name = "basic_lib",
srcs = ["BasicActivity.java"],
javacopts = ["-source 11 -target 11"],
manifest = "AndroidManifest.xml",
resource_files = glob(["res/**"]),
enable_data_binding = True,
)
60 changes: 60 additions & 0 deletions examples/databinding/java/com/basicapp/BasicActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2022 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.basicapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.basicapp.databinding.BasicActivityImpl;

/**
* The main activity of the Basic Sample App.
*/
public class BasicActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic_activity);

final Button buttons[] = {
findViewById(R.id.button_id_fizz), findViewById(R.id.button_id_buzz),
};

for (var b : buttons) {
b.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
TextView tv = findViewById(R.id.text_hello);
if (v.getId() == R.id.button_id_fizz) {
tv.setText("fizz");
} else if (v.getId() == R.id.button_id_buzz) {
tv.setText("buzz");
}
}
});
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>
<import type="android.view.View" />
</data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/text_hello"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button_id_fizz"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="fizz" />
<Button
android:id="@+id/button_id_buzz"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="buzz" />

</LinearLayout>
</layout>
8 changes: 8 additions & 0 deletions examples/databinding/java/com/basicapp/res/menu/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.basicapp.BasicActivity" >
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100" />
</menu>
5 changes: 5 additions & 0 deletions examples/databinding/java/com/basicapp/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
8 changes: 8 additions & 0 deletions examples/databinding/java/com/basicapp/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name" translatable="false">basicapp</string>
<string name="hello_world" translatable="false">Hello world!</string>
<string name="action_settings" translatable="false">Settings</string>

</resources>