Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feature-request: add android_library support to maven distribution #233

Closed
jagobagascon opened this issue Jun 4, 2020 · 6 comments
Closed

Comments

@jagobagascon
Copy link

jagobagascon commented Jun 4, 2020

I'm trying to deploy an android_library to maven, but maven assemble and deployment rules only work with jars, and I need to upload an aar artifact.

I tried modifying the rules myself to make a PR but for some reason aspects are not working when I define the aar as target (and thus pom generation fails). I think it may be a bug with Bazel or the Android rules but I couldn't make it work without having to completely change the deployment rule.

The aar artifact is an implicit output of the android_library rule, which means it's just a file and aspects do not work on them.

assemble_maven(
    name = 'assemble',
    target = ':my_android_lib',
)
assemble_maven(
    name = 'assemble',
    target = ':my_android_lib.aar', # fails because aspects are not executed
)

To make it work I had to modify the deployment so I could generate the pom and then explicitly choose the deployed file:

assemble_maven(
    name = 'generate_pom',
    target = ':build',
)
publish_maven(
    name = 'publish',
    pom_file = ':generate_pom',
    target = ':build.aar',
    sources = ':build.srcjar',
)

Are there any plans on supporting Android aar files?

@lolski
Copy link
Member

lolski commented Jun 19, 2020

Hi! Unfortunately, we have no plans for that in the foreseeable future (we're not building Android products as a company).

What you can do instead is to create your own distribution repository, and it can depend on this repository if you feel that you can build it on top of existing functionalities which we provide.

Closing this issue for now.

@cpsauer
Copy link

cpsauer commented Mar 18, 2021

@jagobagascon, did you end up solving this another way? Was looking into doing the same :)

@jagobagascon
Copy link
Author

@cpsauer I ended up writing my own Bazel rule. As I say in my first comment, I had to split the deployment in two: pom generation and the deployment itself.

The rule to create the pom.xml does just the same as this library (using the Android library we can get the dependencies to generate the pom) and the deployment rule has a target field to define the deployed file. It just calls mvn deploy:deploy-file with the generated pom and the aar file I want to deploy.

# generate pom
generate_pom(
    name = 'generate_pom',
    target = ':my_android_lib', # android_library (only used to generate the pom)
    project_url = project_url,
    project_name = 'my_android_lib',
    packaging = 'aar',
)

# publish calling `bazel run :publish --define version=1.2.3`
publish_to_artifactory(
    name = 'publish',
    pom_file = ':generate_pom',
    target = ':my_android_lib.aar', # deployed artifact
    sources = ':libmy_android_lib-src.jar',
    url = deployment_url,
    requires_auth = True,
    user = GITHUB_ACTOR,
    password = GITHUB_TOKEN,
)

Our repo is not currently public but you can take a look at the relevant Bazel code here: https://gist.github.com/jagobagascon/4e9499eaf69934f14578d3677afc3539

@cpsauer
Copy link

cpsauer commented Mar 18, 2021

Thanks so much @jagobagascon!

I (and everyone else who comes across this in the future) really appreciate it.

@cpsauer
Copy link

cpsauer commented Mar 19, 2021

@jagobagascon, you didn't also solve the issue of bundling up the transitive deps (minus maven deps) into the aar, by any chance, did you? Was tackling that full on and it looks a bit...gnarly.

@jagobagascon
Copy link
Author

I have a bunch of android_librarys that depend on each other but all of them are deployed with maven, so I didn't need to include any transitive deps.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants