Android SDK dependencies 401

While configuring my multiproject(~25 projects atm) a big amout of time wasted trying to fetch android sdk dependencies(see log below).
I save time using --offline, but it seems like i am ignoring a problem.

Does anyone known if it’s a normal behavior?

Failed to get resource: GET. [HTTP HTTP/1.1 401 Unauthorized: http://artifactory.mydomen/artifactory/repo/com/android/support/recyclerview-v7/23.1.1/recyclerview-v7-23.1.1.pom]
Failed to get resource: GET. [HTTP HTTP/1.1 401 Unauthorized: http://artifactory.mydomen/artifactory/repo/com/android/support/design/23.1.1/design-23.1.1.pom]
Failed to get resource: GET. [HTTP HTTP/1.1 401 Unauthorized: http://artifactory.se.mydomen/artifactory/repo/com/android/support/support-v4/23.1.1/support-v4-23.1.1.pom]
Failed to get resource: GET. [HTTP HTTP/1.1 401 Unauthorized: http://artifactory.se.mydomen/artifactory/repo/com/android/support/support-annotations/23.1.1/support-annotations-23.1.1.pom]
Failed to get resource: GET. [HTTP HTTP/1.1 401 Unauthorized: http://artifactory.se.mydomen/artifactory/repo/com/android/support/appcompat-v7/23.1.1/appcompat-v7-23.1.1.pom]

Your build has a repository configured that requires authentication. Have you configured credentials?

Of course, i have a lot of dependencies, all of them resolves correctly, but android sdk dependencies are not there. They can only be in local maven repository. Android gradle plugin somehow hardcodes it. And resolves too, but my problem is a big chunk of time wasted trying to resolve it from artifactory.

my dependencies block looks like this:

allprojects {
    repositories {
        maven { url "${artifactory_contextUrl}/repo" }
    }
}

artifactory allows anonymous access

So it seems the issue is that Gradle is trying to fetch the Android dependencies from your local artifactory. Strange that artifactory is returning a 401 rather than a 404 then. By default Android gets its dependencies from jCenter. You might need to add it to your build script.

repositories {
    jcenter()
}

My artifactory is not so local, its an remote web server.
jCenter is a remote repository too, and there are no public android dependencies sdk there afaik
It’s kinda hack: reroute sdk to maven local repository we all download ($ANDROID_HOME/extras/android/m2repository)
So android gradle plugin know how to do it with jcenter and it’s not triyng to fetch with 404 result, but can’t do it from custom one?

jcenter in front of artifactory is not what i want, the goal of artifactory was a mirror proxy(with faster resolve), and in this scenario it will fallback from jcenter to artifactory.

about 401: its strange artifactory settings, in fact it is not found, but some mess in permissions…

By “local” I mean that it’s your own Artifactory. Not a “public” server.

Another option is to configure Artifactory to proxy to jcenter for stuff it can’t find.

It was already configured as jcenter proxy

I think I’m potentially confused as to what you are trying to do, what broke when, and what is different from what you are doing from what Android Studio configured by default?

So as I understand it now you have a local maven repo located at $ANDROID_HOME/extras/android/m2repository. Is your issue that you are not able to configure this as a local Maven repository?

  1. only jcenter() - magic local repository smart enough not to fetch android sdk from remote
  2. only artifactory - it tries to resolve android sdk from remote and it wastes a lot of build time

You could introduce a #3 which is Artifactory + local SDK repo.

repositories {
    maven {
        url "file://${System.env['ANDROID_HOME']}/extras/android/m2repository"
    }
    maven {
        url // artifactory url
    }
}

Thanks Mark! I finally got it to work.
For both CI and local.

def getSdkDirFromLocalProperties() {
    def rootDir = project.rootDir
    def localProperties = new File(rootDir, "local.properties")
    Properties properties = new Properties()
    localProperties.withInputStream { instr ->
        properties.load(instr)
    }
    properties.getProperty('sdk.dir')
}

def androidHome = System.env['ANDROID_HOME']

def androidHomeIsDefined = androidHome?.trim()

def sdkDir = androidHomeIsDefined ? androidHome : getSdkDirFromLocalProperties()

println "SDK dir: $sdkDir"

allprojects {
    repositories {
        maven { url "file://$sdkDir/extras/android/m2repository" }
        maven { url "file://$sdkDir/extras/google/m2repository" }
        maven { url "${artifactory_contextUrl}/repo" }
    }
}