Andrew
Andrew

Reputation: 21076

Gradle looking for aar in wrong project's lib folder

I have an Android application made up of multiple projects. One of those projects is an App project that just extends the Application object.

Inside the build.gradle for that app project, I add other projects as dependencies.

I've just created a new module to house an SDK (aar) I want to use. I've also added it to my app project's build.gradle.

compile project(':newmodule-thesdk')

Inside the libs folder of newmodule-thesdk, I have added the aar file. We'll call it thesdk.aar.

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile(name:'thesdk-1.0', ext:'aar')
}

When I attempt to sync gradle, the sync fails because thesdk-1.0 does not exist in the libs folder of my app project. Why is it looking for it there? Why is it not just finding it in the newmodule-thesdk project?

Upvotes: 12

Views: 689

Answers (4)

JAAD
JAAD

Reputation: 12379

u could do 2 approaches

1) As you already said it:

 repositories {
        flatDir {
            dirs project(':newmodule-thesdk').file('libs')
        }
    }

it can be done in this way

2)you can make a new gradle project with including the sdk and reference the old code project in it.

and then reference old project when u dont want to include the sdk and when you want to include the sdk reference the new gradle project

Upvotes: 0

El Don
El Don

Reputation: 912

You just have to change your code this way

dependencies {
    compile fileTree(include: ['thesdk-1.0.aar'], dir: 'libs')
}

Keep in mind that the file should exist!

Upvotes: 0

Andrew
Andrew

Reputation: 21076

It appears solving the problem required me to do the following in my App project's build.gradle.

    repositories {
        flatDir {
            dirs project(':newmodule-thesdk').file('libs')
        }
    }

Upvotes: 4

Alexander Tumanin
Alexander Tumanin

Reputation: 1842

I had the similar problem and I just changed my xxx.aar to xxx-N.N.aar, in your case thesdk.aar to thesdk-1.0.aar and then it worked fine

Upvotes: 0

Related Questions