Android Studio - Building library aar file doesn't append flavor or buildType to output

181 views Asked by At

I am running assemble for my library module , I see from logs that it should generate two files myLib-release.aar and myLib-debug.aar inside the myLib/build/outputs/ folder.

However, I always only find one lib there that is myLib.aar, it doesn't matter if I run assemble for both, assembleDbug or assembleRelease.

Why is this happening?

1

There are 1 answers

0
htafoya On

According to this discussion it is an error (or planned feature) in gradle, up to date it is still the same.

https://github.com/gradle/gradle/issues/8328

Workaround can be to implement this:

// in library/library.gradle
afterEvaluate {
    def debugFile = file("$buildDir/outputs/aar/library.aar")
    tasks.named("assembleDebug").configure {
        doLast {
            debugFile.renameTo("$buildDir/outputs/aar/library-debug.aar")
        }
    }
    tasks.named("assembleRelease").configure {
        doLast {
            debugFile.renameTo("$buildDir/outputs/aar/library-release.aar")
        }
    }
}

You may then implement copy tasks as desired.