Hello guys! I have an `.aar` library, which is lo...
# gradle
u
Hello guys! I have an
.aar
library, which is located on the project level:
libs/lib.aar
. I declare it in an Android Library module in the following manner:
Copy code
implementation files('libs/lib.aar')
After updating to the latest Android Gradle Plugin:
Copy code
-classpath 'com.android.tools.build:gradle:3.5.3'
 +classpath 'com.android.tools.build:gradle:7.0.0-beta02'
I got this error message:
Copy code
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error)
The only thing I could find on Stackoverflow was the following: https://stackoverflow.com/questions/60878599/error-building-android-library-direct-local-aar-file-dependencies-are-not-supp But these solutions seem outdated. Following official documentation here didn’t help either. Did someone encounter this issue? Need help! 🆘
p
I had recently bumped into this as well. asked on gradle slack. there seems to be no real reason to enforce this limitations by AGP plugin. Just “purity clean code” forces you to refactor your build config. I think it may make sense to report to google bugtracker asking for explanation and hoping to revert the limitation. https://gradle-community.slack.com/archives/CJYS1DAP5/p1620406352107700
Use AGP 4.2.1 for now? Or do you need 7.0 for compose?
u
@plastiv, thanks for answering. We would like to switch to the latest Android Gradle plugin, hoping to start integrating compose. Did you encounter this issue also on AGP 4.2.1?
p
I had to fool tool around with pretending that .aar is served by “real” maven repo with
Copy code
subprojects {
    repositories {
        maven {
            url "${rootProject.projectDir}/libs"
            metadataSources {
                artifact()
            }
            content {
                includeModule("com.snowplowanalytics", "jetified-snowplow-android-tracker")
            }
        }
    }
}
u
did it work?
p
Then just put .aar into folder libs/com/snowplowanalytics/jetified-snowplow-android-tracker/jetified-snowplow-android-tracker.aar equivalent for your library
It works for now. Maybe AGP will update their linter to be more strict who knows. Kinda seems to be “official” workaround https://issuetracker.google.com/issues/159873430
u
these are the bad news(
n
The reason this is enforced is that the correct behavior cannot be guaranteed for
.aar
files with library resource. This is why the functionality was removed
p
Are there any description/sample/bugtracker/sourcecode with pointing out what doesn’t (shouldn’t) work exactly?
Something concrete, like A -> B -> C.aar with databinding_layout.xml couldn’t be fully read in A by AGP. I’m struggling to understand if my use case have an issue or not. I have a 3rd party provider which ships their sdk as .aar . Not good, not terrible and also works okay for years.
u
@no, so if a correct behavior is not guaranteed, how one should use add aar libraries to projects?
n
you can use it from a maven repository. that maven dependency will ensure that all the dependencies are declared in the maven pom and are therefore downloaded. the file won't have the dependency information
u
you mean from local maven repository?
n
either local or remote. doesn't matter
u
i do not have any experience with local maven repository. could you suggest some kind of guide?
u
thanks. i’ll wait for an official solution while using this workaround
e
But these solutions seem outdated.
Well, the stackoverflow answer was operated by IDE, though the menu is gone, but you can make it work with Gradle directly: Create a
build.gradle.kts
with following code, and put your
.aar
file along with it to create an aar module
configurations.maybeCreate("default")
artifacts.add("default", file("filename.aar"))
u
@El Zhang, interesting, thanks. where do I put this gradle file? Also, we don’t use kotlin dsl for gradle.
e
Just make a directory let say "dummy-module", put the Gradle file and your aar into it. Other modules can refer the "dummy- module" by implementation(...). That's it. For Groovy DSL, should be similar, can try from your end.
👍 1
n
That is the official solution. Why do you need to use an aar dependency from the local file system? Do you depend on jar files in the same way?
u
Because we didn’t publish this library anywhere. But today we switched to GitHub Packages for this library distribution.
n
You can also use an included build or composite build to depend on this artifact by adding the gradle build of this project to your other project. https://docs.gradle.org/current/userguide/composite_builds.html
332 Views