Skip to content

Commit

Permalink
Add android rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Sep 28, 2018
1 parent 6d71c37 commit 42a80ef
Showing 21 changed files with 855 additions and 0 deletions.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2016 PubRef.org

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.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,6 +21,11 @@ are in a pre-release status. The primary goals are:
3. Minimal dependency loading. Proto rules should not pull in more dependencies
than they absolutely need.

> NOTE: These rules are in a *pre-release* state. The routeguide examples have
> been developed thus far with the goal of getting them to compile/build, not to
> ensure the routeguide client/server is actually correct. Do expect everything
> to compile, but not to work right!
## Usage

### Add rules_proto your `WORKSPACE`
39 changes: 39 additions & 0 deletions android/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

load("//:plugin.bzl", "proto_plugin")

proto_plugin(
name = "javalite",
out = "%{name}.jar",
options = ["lite"],
tool = "@com_google_protobuf_lite//:protoc_gen_javalite",
visibility = ["//visibility:public"],
)

proto_plugin(
name = "grpc_javalite",
out = "%{name}.jar",
options = ["lite"],
tool = "@io_grpc_grpc_java//compiler:grpc_java_plugin",
visibility = ["//visibility:public"],
)

java_library(
name = "proto_deps",
exports = [
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
"@javax_annotation_javax_annotation_api//jar",
],
visibility = ["//visibility:public"],
)

java_library(
name = "grpc_deps",
exports = [
":proto_deps",
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//protobuf-lite",
"@io_grpc_grpc_java//stub",
],
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions android/compile.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("//:compile.bzl", "proto_compile")

def android_proto_compile(**kwargs):
proto_compile(
plugins = [str(Label("//android:java"))],
**kwargs
)

def android_grpc_compile(**kwargs):
proto_compile(
plugins = [str(Label("//android:javalite")), str(Label("//android:grpc_javalite"))],
#plugins = [str(Label("//android:grpc_java"))],
**kwargs
)

41 changes: 41 additions & 0 deletions android/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def android_proto_compile_deps(
rules_android_version = "60f03a20cefbe1e110ae0ac7f25359822e9ea24a",
rules_android_sha256 = "4305b6cf6b098752a19fdb1abdc9ae2e069f5ff61359bfc3c752e4b4c862d18e",
protobuf_lite_version = "5e8916e881c573c5d83980197a6f783c132d4276",
protobuf_lite_sha256 = "d35902fb3cbe9afa67aad4e615a8224d0a531b8c06d32e100bdb235244748a3d",
gmaven_tag = "20180927-1",
gmaven_sha256 = "ddaa0f5811253e82f67ee637dc8caf3989e4517bac0368355215b0dcfa9844d6",
):
existing = native.existing_rules()
if "build_bazel_rules_android" not in existing:
http_archive(
name = "build_bazel_rules_android",
urls = ["https://github.com/bazelbuild/rules_android/archive/%s.tar.gz" % rules_android_version],
strip_prefix = "rules_android-%s" % rules_android_version,
sha256 = rules_android_sha256,
)
if "com_google_protobuf_lite" not in existing:
http_archive(
name = "com_google_protobuf_lite",
urls = ["https://github.com/protocolbuffers/protobuf/archive/%s.tar.gz" % protobuf_lite_version],
strip_prefix = "protobuf-%s" % protobuf_lite_version,
sha256 = protobuf_lite_sha256,
)

# if "android_sdk_tools" not in existing:
# http_archive(
# name = "android_sdk_tools",
# urls = ["https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"],
# #strip_prefix = "protobuf-%s" % protobuf_lite_version,
# #sha256 = protobuf_lite_sha256,
# )
if "gmaven_rules" not in existing:
http_archive(
name = "gmaven_rules",
strip_prefix = "gmaven_rules-%s" % gmaven_tag,
urls = ["https://github.com/bazelbuild/gmaven_rules/archive/%s.tar.gz" % gmaven_tag],
sha256 = gmaven_sha256,
)

19 changes: 19 additions & 0 deletions android/example/proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


load("//android:compile.bzl", "android_grpc_compile")
#load("//android:library.bzl", "android_grpc_library")

android_grpc_compile(
name = "routeguide",
deps = [
"//example/proto/routeguide:proto_library",
],
# verbose = 2,
)

# android_grpc_library(
# name = "routeguide_lib",
# deps = [
# "//example/proto/routeguide:proto_library",
# ],
# )
25 changes: 25 additions & 0 deletions android/example/routeguide/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.grpc.routeguideexample">

<uses-permission android:name="android.permission.INTERNET" />

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<application android:allowBackup="false"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".RouteGuideActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
34 changes: 34 additions & 0 deletions android/example/routeguide/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//android:library.bzl", "android_grpc_library")
load("@gmaven_rules//:defs.bzl", "gmaven_artifact")

android_grpc_library(
name = "routeguide",
deps = ["//example/proto/routeguide:proto_library"],
)

# android_library(
# name = "clientlib",
# manifest = "AndroidManifest.xml",
# custom_package = "io.grpc.routeguideexample",

# )

# NOTE: at the moment this is not a routeguide client at all. Only testing that
# we can compile and reference an android_grpc_library in an android_binary and
# not have it crash.
android_binary(
name = 'client',
manifest = 'AndroidManifest.xml',
custom_package = 'io.grpc.routeguideexample',
#proguard_specs = ["proguard-rules.pro"],
multidex = 'native',
resource_files = glob(["src/main/res/**"]),
srcs = glob(["src/main/java/**"]),
deps = [
":routeguide",
"@com_android_support_appcompat_v7_28_0_0//aar",
#gmaven_artifact("com.android.support:appcompat-v7:28.0.0"),
],
#'@com_android_support_design_27_0_1//aar',
#gmaven_artifact("com.google.android.gms:play-services:aar:12.0.0"),
)
17 changes: 17 additions & 0 deletions android/example/routeguide/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in $ANDROID_HOME/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.**
-dontwarn javax.naming.**
-dontwarn okio.**
# Ignores: can't find referenced class javax.lang.model.element.Modifier
-dontwarn com.google.errorprone.annotations.**
Loading

0 comments on commit 42a80ef

Please sign in to comment.