aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_defs/repo/android.bzl
blob: 1e0e9caf0a2469e64a70de88134c28a979082d73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright 2018 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.
"""Rules for importing external Android Archives (AARs).

Usage:

    # In WORKSPACE
    load("@bazel_tools//tools/build_defs/repo:android.bzl", "aar_import_external", "aar_maven_import_external")

    # Specify the URL directly:
    aar_import_external(
        name = "com_android_support_preference_v14_25_1_0",                              # required
        licenses = ["notice"],                                                           # required
        aar_urls = [                                                                     # required
            "https://dl.google.com/dl/android/maven2/com/android/support/preference-v14/25.1.0/preference-v14-25.1.0.aar"
        ],
        aar_sha256 = "442473fe5c395ebef26c14eb01d17ceda33ad207a4cc23a32a2ad95b87edfabb", # optional or empty string
        deps = [                                                                         # optional or empty list
            "@com_android_support_recyclerview_v7_25_1_0//aar",
            "@com_android_support_appcompat_v7_25_1_0//aar",
            "@com_android_support_preference_v7_25_1_0//aar",
            "@com_android_support_support_v4_25_1_0//aar",
        ],
    )

    # Or, specify the artifact coordinate:
    aar_maven_import_external(
        name = "com_android_support_preference_v14_25_1_0",                         # required
        artifact = "com.android.support.test:preference-v14:25.1.0",                # required
        sha256 = "442473fe5c395ebef26c14eb01d17ceda33ad207a4cc23a32a2ad95b87edfabb" # optional or empty string
        licenses = ["notice"],                                                      # required
        server_urls = ["https://maven.google.com"],                                 # required
        deps = [                                                                    # optional or empty list
            "@com_android_support_recyclerview_v7_25_1_0//aar",
            "@com_android_support_appcompat_v7_25_1_0//aar",
            "@com_android_support_preference_v7_25_1_0//aar",
            "@com_android_support_support_v4_25_1_0//aar",
        ],
    )

    # In BUILD.bazel
    android_library(
        name = "foo",
        srcs = [...],
        deps = [
            "@com_android_support_preference_v14_25_1_0//aar",
        ],
    )
"""

load(":jvm.bzl", "convert_artifact_coordinate_to_urls", "jvm_import_external")

def aar_import_external(aar_sha256, aar_urls, **kwargs):
    jvm_import_external(
        rule_name = "aar_import",
        rule_metadata = {
            "extension": "aar",
            "import_attr": "aar = %s",
        },
        artifact_sha256 = aar_sha256,
        artifact_urls = aar_urls,
        **kwargs
    )

def aar_maven_import_external(artifact, server_urls, aar_sha256 = "", **kwargs):
    aar_import_external(
        aar_sha256 = aar_sha256,
        aar_urls = convert_artifact_coordinate_to_urls(
            artifact,
            server_urls,
            "aar",
        ),
        **kwargs
    )