-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic bzlmod example #148
Draft
keith
wants to merge
2
commits into
bazelbuild:main
Choose a base branch
from
keith:ks/add-basic-bzlmod-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
common --enable_bzlmod --lockfile_mode=off | ||
|
||
# Disabled to avoid //external:android deps in bazel itself | ||
common --android_sdk=@androidsdk//:sdk | ||
common --optimizing_dexer=//:optimizing_dexer | ||
|
||
# Flags needed while the Android rules are being migrated to Starlark. | ||
build --experimental_google_legacy_api | ||
build --experimental_enable_android_migration_apis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rolling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Empty build file to satisfy gazelle for rules_go. | ||
|
||
cc_binary( | ||
name = "optimizing_dexer", | ||
srcs = ["main.cc"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module(name = "basic-example") | ||
|
||
bazel_dep(name = "rules_java", version = "6.4.0") | ||
bazel_dep(name = "rules_android", version = "1") | ||
local_path_override( | ||
module_name = "rules_android", | ||
path = "../../", | ||
) | ||
|
||
android_sdk_extension = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_extension") | ||
use_repo(android_sdk_extension, "androidsdk") | ||
|
||
register_toolchains("@androidsdk//:all") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
To build, ensure the `ANDROID_HOME` and `ANDROID_NDK_HOME` environment variables are set, and run: | ||
|
||
``` | ||
bazel build java/com/basicapp:basic_app | ||
``` | ||
|
||
See the `.bazelrc` file for flags needed to build the app. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") | ||
load("@rules_android//:android_sdk_supplemental_repository.bzl", "android_sdk_supplemental_repository") | ||
|
||
maybe( | ||
android_ndk_repository, | ||
name = "androidndk", | ||
) | ||
|
||
# This can be removed once https://github.com/bazelbuild/bazel/commit/773b50f979b8f40e73cf547049bb8e1114fb670a | ||
# is released, or android_sdk_repository is properly Starlarkified and dexdump | ||
# added there. | ||
android_sdk_supplemental_repository(name = "androidsdk-supplemental") |
22 changes: 22 additions & 0 deletions
22
examples/basicappbzlmod/java/com/basicapp/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.basic" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="18" | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@rules_android//android:rules.bzl", "android_binary", "android_library") | ||
|
||
android_binary( | ||
name = "basic_app", | ||
manifest = "AndroidManifest.xml", | ||
deps = [":basic_lib"], | ||
) | ||
|
||
android_library( | ||
name = "basic_lib", | ||
srcs = ["BasicActivity.java"], | ||
manifest = "AndroidManifest.xml", | ||
resource_files = glob(["res/**"]), | ||
) |
59 changes: 59 additions & 0 deletions
59
examples/basicappbzlmod/java/com/basicapp/BasicActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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; | ||
|
||
/** | ||
* 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 (Button 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; | ||
} | ||
} |
Binary file added
BIN
+1.64 KB
examples/basicappbzlmod/java/com/basicapp/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.25 KB
examples/basicappbzlmod/java/com/basicapp/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.77 KB
examples/basicappbzlmod/java/com/basicapp/res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.09 KB
examples/basicappbzlmod/java/com/basicapp/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
examples/basicappbzlmod/java/com/basicapp/res/layout/basic_activity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
5
examples/basicappbzlmod/java/com/basicapp/res/values/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
8
examples/basicappbzlmod/java/com/basicapp/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main() { | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a workaround to avoid having this target in bazel reference
//external:android