Skip to content
Open
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
61 changes: 61 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,64 @@ 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
? "--@rules_android//rules/flags:databinding_use_androidx"
build_targets:
- "//java/com/databindingapp:databindingapp"
ubuntu2004_databinding_bzlmod:
name: "Databinding Basic app ubuntu bzlmod"
platform: ubuntu2004
working_directory: examples/databinding
build_flags:
<<: *rules_flags
? "--enable_bzlmod"
? "--enable_workspace=false"
? "--@rules_android//rules/flags:databinding_use_androidx"
build_targets:
- "//java/com/databindingapp:databindingapp"
macos_arm64_databinding:
name: "Databinding Basic app mac arm64"
platform: macos_arm64
working_directory: examples/databinding
build_flags:
<<: *rules_flags
? "--@rules_android//rules/flags:databinding_use_androidx"
build_targets:
- "//java/com/databindingapp:databindingapp"
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"
? "--@rules_android//rules/flags:databinding_use_androidx"
build_targets:
- "//java/com/databindingapp:databindingapp"
# n.b. The below do not build.
# windows_databinding_bzlmod:
# name: "Databinding Basic app Windows Bzlmod"
# platform: windows
# working_directory: examples/databinding
# build_flags:
# <<: *rules_flags
# ? "--enable_bzlmod"
# ? "--enable_workspace=false"
# ? "--@rules_android//rules/flags:databinding_use_androidx"
# build_targets:
# - "//java/com/databindingapp:databindingapp"
# windows_databinding:
# name: "Databinding Basic app Windows"
# platform: windows
# working_directory: examples/databinding
# build_flags:
# <<: *rules_flags
# ? "--@rules_android//rules/flags:databinding_use_androidx"
# build_targets:
# - "//java/com/databindingapp:databindingapp"
3 changes: 2 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
common --java_runtime_version=17
common --java_runtime_version=remotejdk_17
common --tool_java_runtime_version=remotejdk_17
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ maven.install(
],
# To generate, run:
# REPIN=1 bazelisk run --enable_bzlmod @rules_android_maven//:pin
# lock_file = "//:rules_android_maven_install.json",
lock_file = "//:rules_android_maven_install.json",
use_starlark_android_rules = True,
)
use_repo(
Expand Down
9 changes: 9 additions & 0 deletions examples/databinding/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
common:core_library_desugaring --desugar_java8_libs

common --java_runtime_version=remotejdk_17
common --tool_java_runtime_version=remotejdk_17

# 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.
52 changes: 52 additions & 0 deletions examples/databinding/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module(
name = "databinding",
)

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

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

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")


maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "maven",
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
artifacts = [
"androidx.annotation:annotation-jvm:1.9.1",
"androidx.databinding:databinding-adapters:8.7.0",
"androidx.databinding:databinding-runtime:8.7.0",
],
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
"https://repo.gradle.org/gradle/libs-releases",
],
# To generate, run:
# REPIN=1 bazelisk run --enable_bzlmod @maven//:pin
# lock_file = "//:maven_install.json",
use_starlark_android_rules = True,
)
use_repo(
maven,
"maven",
)
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.
60 changes: 60 additions & 0 deletions examples/databinding/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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.

# Android rules dependencies
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()

##### rules_java setup for rules_android #####
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
rules_java_dependencies()
# note that the following line is what is minimally required from protobuf for the java rules
# consider using the protobuf_deps() public API from @com_google_protobuf//:protobuf_deps.bzl
load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features") # buildifier: disable=bzl-visibility
proto_bazel_features(name = "proto_bazel_features")
# register toolchains
load("@rules_java//java:repositories.bzl", "rules_java_toolchains")
rules_java_toolchains()

##### rules_jvm_external setup for rules_android #####
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
rules_jvm_external_deps()
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
name = "maven",
artifacts = [
"androidx.annotation:annotation-jvm:1.9.1",
"androidx.databinding:databinding-adapters:8.7.0",
"androidx.databinding:databinding-runtime:8.7.0",
"com.google.protobuf:protobuf-java:4.27.2",
"com.google.protobuf:protobuf-java-util:4.27.2",
],
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
"https://repo.gradle.org/gradle/libs-releases",
],
)

##### rules_android setup #####
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()

# Android SDK setup
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/databindingapp/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.databindingapp" >

<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.databindingapp.DataBindingMainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
24 changes: 24 additions & 0 deletions examples/databinding/java/com/databindingapp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@rules_android//android:rules.bzl", "android_binary", "android_library")

android_binary(
name = "databindingapp",
manifest = "AndroidManifest.xml",
enable_data_binding = True,
deps = [
":databinding_lib",
"@maven//:androidx_databinding_databinding_runtime",
],
)

android_library(
name = "databinding_lib",
srcs = ["DataBindingMainActivity.java"],
manifest = "AndroidManifest.xml",
resource_files = glob(["res/**"]),
enable_data_binding = True,
deps = [
"@maven//:androidx_annotation_annotation_jvm",
"@maven//:androidx_databinding_databinding_adapters",
"@maven//:androidx_databinding_databinding_runtime",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.databindingapp;

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.databindingapp.databinding.ActivityDataBindingBinding;

import java.util.Random;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActivityDataBindingBinding binding = ActivityDataBindingBinding.inflate(getLayoutInflater());

Random random = new Random();
binding.setShowFizz(random.nextDouble() < 0.5);
binding.setShowBuzz(random.nextDouble() < 0.5);

setContentView(binding.getRoot());
}

@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,39 @@
<?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" />
<variable name="showBuzz" type="Boolean" />
<variable name="showFizz" type="Boolean" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

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

<Button
android:id="@+id/fizzButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="fizz"
android:visibility="@{showFizz ? View.VISIBLE : View.GONE}"
/>
<Button
android:id="@+id/buzzButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="buzz"
android:visibility="@{showBuzz ? View.VISIBLE : View.GONE}"
/>

</LinearLayout>
</layout>
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>
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>
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">Data Binding App</string>
<string name="hello_world" translatable="false">Hello world!</string>
<string name="action_settings" translatable="false">Settings</string>

</resources>
3 changes: 2 additions & 1 deletion rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ load("@bazel_skylib//rules:common_settings.bzl", "int_setting")
load("@rules_java//java:defs.bzl", "java_library")

exports_files([
"data_binding_annotation_template.txt",
"data_binding_annotation_template_androidx.txt",
"data_binding_annotation_template_support_lib.txt",
"res_v3_dummy_AndroidManifest.xml",
"res_v3_dummy_R.txt",
"robolectric_properties_template.txt",
Expand Down
Loading