Skip to content
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

android_import_external #4654

Closed
ronshapiro opened this issue Feb 19, 2018 · 7 comments
Closed

android_import_external #4654

ronshapiro opened this issue Feb 19, 2018 · 7 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) type: feature request

Comments

@ronshapiro
Copy link
Contributor

Description of the problem / feature request:

java_import_external is awesome. We should add an Android equivalent for .aar files.

Have you found anything relevant by searching the web?

Somewhat related: https://groups.google.com/d/msg/bazel-discuss/t0BOBD9UYn0/1YEvlZQHAwAJ

@ronshapiro ronshapiro changed the title android_import_external for Android libraries that want to advantage of java_import_externals android_import_external Feb 19, 2018
@jin
Copy link
Member

jin commented Feb 19, 2018

There's aar_import and maven_aar. maven_aar is unfortunately not documented yet. It also shells out to a local mvn install.

I'm not sure what's the future is on resolving remote AAR and JAR dependencies. @cgrushko, are you still planning on deprecatingmaven_jar?

@jin
Copy link
Member

jin commented Feb 19, 2018

cc @aj-michael

@jin
Copy link
Member

jin commented Feb 19, 2018

It doesn't seem too nontrivial to adapt the java_import_external implementation to use aar_import.

@ittaiz
Copy link
Member

ittaiz commented Feb 19, 2018 via email

@ahumesky ahumesky added the P2 We'll consider working on this in future. (Assignee optional) label Feb 27, 2018
@jin
Copy link
Member

jin commented Apr 16, 2018

I've implemented aar_import_external for use in gmaven_rules. I'll see how I can bring this upstream to either Bazel or the upcoming Skylark home at https://github.com/bazelbuild/rules_android

The use case is specific to gmaven_rules because gmaven_rules resolves and generates targets automatically. I agree with @ittaiz that it's low-level and there can be an intermediary abstraction to resolve coordinates to URLs. In gmaven_rules, there's a gmaven_artifact macro that converts an artifact coordinate to the generated target name.

@ittaiz
Copy link
Member

ittaiz commented Apr 16, 2018 via email

@jart
Copy link
Contributor

jart commented May 11, 2018

I recommend using java_import_external with verbatim URLs. We need to be able to grep URLs (see GitHub BigQuery dataset) to offer high availability mirroring via mirror.bazel.build. Folks who do things like https://%s or maven:abbreviation:v1 will miss out on those reliability and performance benefits. Yes it makes your WORKSPACE file ugly, but it's worth it.

bazel-io pushed a commit that referenced this issue May 29, 2018
This PR copies "upstream" a change made to java_import_external in`rules_scala` (see [PR](bazelbuild/rules_scala#473))

This change was originally proposed by @dslomov [here](#3528) (search for 'jvm_import_external')

java_import_external was changed to `jvm_import_external` 'template like' rule + `java_import_external` macro in order to allow for other jvm languages (e.g. scala and kotlin) to utilize the 'import_external' functionality without copying the boiler plate again and again.

This has already been used in `rules_scala` with the introduction of `scala_import_external` and `scala_maven_import_external`

In addition to the `import rule name`, `jvm_import_external` can also be called with custom attributes needed by the underlying import rules, as well as a custom load statement.

`java_import_external` is used as a macro in rules_scala to make sure it's still functioning properly after the change.

`jvm_maven_import_external` exposes maven artifact terminology.
This will also allow to create a `maven_import_external` macro that will delegate to `jvm_maven_import_external` with a `maven_import` rule which will have `MavenCoordinates` Provider as discussed [here](#4654)

Closes #5068.

PiperOrigin-RevId: 198398621
@jin jin self-assigned this Jun 8, 2018
werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
Usage example:

```python
# 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",
    ],
)
```

To test this out with gmaven_rules, change the `load` statement in https://github.com/bazelbuild/gmaven_rules/blob/master/gmaven.bzl to

```
load('@bazel_tools//tools/build_defs/repo:android.bzl', 'aar_import_external')
load('@bazel_tools//tools/build_defs/repo:java.bzl', 'java_import_external')
```

Fixes bazelbuild#4654

RELNOTES: New rules for importing Android dependencies: `aar_import_external` and `aar_maven_import_external`. `aar_import_external` enables specifying external AAR dependencies using a list of HTTP URLs for the artifact. `aar_maven_import_external` enables specifying external AAR dependencies using the artifact coordinate and a list of server URLs.

Closes bazelbuild#5319.

Change-Id: I9517e68ab78f2e30fb6ceabfe3b35061c585d607
PiperOrigin-RevId: 199839047
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants