user5981074 user5981074 - 3 months ago 20
Android Question

Gradle flatDir path to module

I have an Android project divided into two modules: app (main application) and mylibrary. I have an myaarfile.aar file that I want to add to mylibrary. I work on MacOSX (not sure if that's important).

In mylibrary

gradle
file I have specified:

compile(name:'myaarfile', ext:'aar')


and in global gradle file I've put this:

allprojects {
repositories {
jcenter()
flatDir {
dirs 'file:/Users/myuser/myproject/mylibrary/libs'
}
}
}


and it works fine. But there's an obvious issue with this path and I'd like to make it universal. But changing it to:

dirs '${rootDir}/libs'


didn't work, cause gradle was looking for the aar in:


file:/Users/myuser/myproject/mylibrary/${rootDir}/libs/myaarfile.aar


changing the path to:

dirs '/libs'


didn't work either, cause gradle was looking for aar in:


file:/libs/myaarfile.aar


How should I specify the path so gradle would search for the aar in correct folder? Unfortunately I can't use another method to add the aar.

EDIT:

Found it!

flatDir {
dirs "${project(':mylibrary').projectDir}/libs"
}

Answer

Found it!

flatDir {
    dirs "${project(':mylibrary').projectDir}/libs"
}