Home » Android » android – Gradle looking for aar in wrong project's lib folder

android – Gradle looking for aar in wrong project's lib folder

Posted by: admin May 14, 2020 Leave a comment

Questions:

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?

How to&Answers:

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')
        }
    }

Answer:

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

Answer:

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!

Answer:

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