6

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"
}

2 Answers 2

5

Found it!

flatDir {
    dirs "${project(':mylibrary').projectDir}/libs"
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

dirs 'libs'

That works in this project:

https://github.com/CUTR-at-USF/usf-step-sensor-demo/blob/master/app/build.gradle

2 Comments

That worked but only if I put the aar into main module (app/libs folder). If it's in mylibrary/libs I had to use the path from the 'EDIT'.
Gotcha! Go ahead and put your EDIT answer into a real answer below, if that solved it. It's ok to answer your own questions, you'll just need to wait a few days until you can officially mark it as the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.