Search code examples
androidgradleaar

Android Gradle not finding remote AAR


I was working with Gradle v5.4 and Android Gradle Plugin v3.5.2, and had no problems!

I have a remote Artifactory repository where I upload .aar files that are needed in my project.

When I updated to Gradle v6.5 and Android Gradle Plugin v4.0.1 those .aar files are no longer downloaded.

This is how I add those dependencies:

implementation "ar.com.sebasira:some-library:1.0.0@aar"

This was working just fine before the upgrade.

In the logs I can see that AndroidStudio looks for it in this location:

https://myrepo.com.ar/ar/com/sebasira/some-library/1.0.0/some-library-1.0.0.pom

If I put that URL in the browser, indeed there's nothing to be found, but if I change the last part (the extension) to .aar I can download the artifact.

I thought that adding @aar was to instruct Gradle to look for .aar file but it seems not to be working.

I've also try adding the dependency like in this other way with no luck.

implementation group: 'ar.com.sebasira', name: 'some-library', version: '1.0.0', ext: 'aar'

Solution

  • I've found out that since Gradle v6.0 onwards, Gradle assumes that if no .pom file is present in the remote repository is because the artifact does not exists, so it does not look for it by default. According to release notes:

    If Gradle fails to locate the metadata file (.pom or ivy.xml) of a module in a repository defined in the repositories { } section, it now assumes that the module does not exist in that repository.

    ...

    You can opt into the old behavior for selected repositories by adding the artifact() metadata source.

    So the solution is to add that to repository in question, like this:

    repositories {
        maven {
            url 'the-repo-url'
            metadataSources {
                artifact()
            }
        }
    }