1 year ago

#319301

test-img

SY MY

Android Library .aar file dependencies are not supported using flatDir, Gradle 7+

I got 2 questions to ask. I tried Google and all stackoverflow similar question but I couldn't find a solution. Appreciate it much if you could help, thanks.

I have upgraded to honeycomb, target & compileSDKVersion 31, buildToolsVersion '31.0.0'and using gradle version 7.2. Big problem is lots of implementation in app>build.gradle & project>build.gradle need to be removed because it changes to be placed in just settings.gradle (dependencyResolutionManagement).

My first question is,

In Project > Buildgradle :

allProject{
  flatDir {
             dirs 'libs'
             dirs project(':libraries:softtoken').file('libs')
         }
  }

In App > Buildgradle :

//repositories {
//    flatDir {
//        dirs 'libs'
//    }
//    mavenCentral()
//}

These 2 no longer able to include in settings.gradle dependencyResolutionManagement{}.

This create an issue in my project, I got multiple aar files in my Android Library module > Libs folder. For example, money1-debug.aar, money1-release.aar and money2.aar

My App > build.gradle
//    debugImplementation project(path: ':libraries:money', configuration: 'debug')
//    uatImplementation project(path: ':libraries:money', configuration: 'uat')
//    uatImplementation project(path: ':libraries:money', configuration: 'release')

How I implemented it in my Android Library Money module->Build.gradle, By using
debugImplementation (name: ' money1-debug', ext: 'aar') uatImplementation (name: 'money1-release', ext: 'aar') releaseImplementation(name: 'money2', ext: 'aar')

Above allow me to build different variant such as (debug, uat and release) using different aar files in the Android Library->libs folder.

I did find a new way by creating new aar/jar module and add below in build.gradle :

configurations.maybeCreate("default") artifacts.add("default", file('[nameOfTheAar].aar'))

so my case, i will add multiple

artifacts.add("default", file("libs/money1-debug.aar")) 
artifacts.add("default", file("libs/money1-release.aar")) 
artifacts.add("default", file("libs/money2.aar")) 

settings gradle
include(":MoneyAARDirectory")

Here is my question how to put it in the app build.gradle and other Android Library build.gradle so they can get connected to the multiple aars for different build variants.

My App > build.gradle 
//    debugImplementation project(path: ':MoneyAARDirectory/libs', configuration: 'debug')
//    uatImplementation project(path: ':MoneyAARDirectory/libs', configuration: 'uat')
//    uatImplementation project(path: ':MoneyAARDirectory/libs', configuration: 'release')

:MoneyAARDirectory/libs or :MoneyAARDirectory ? and then in the Android Money library how to implement ?

Android Money Library : 
implementation project(":MoneyAARDirectory/libs/money1-debug.aar", configuration = "debug")
implementation project(":MoneyAARDirectory/libs/money1-release", configuration = "uat")
implementation project(":MoneyAARDirectory/libs/money2", configuration = "release")

or

implementation project(":MoneyAARDirectory/libs", configuration="default")
debugImplementation (name: 'money1-debug', ext: 'aar')
uatImplementation (name: 'money1-release', ext: 'aar')
releaseImplementation(name: 'money2', ext: 'aar')

I think it is confusing because previously the flatDir can be used, and my method is just add the same things as below in both App buildgradle and Android Money Library build gradle :

debugImplementation (name: 'money1-debug', ext: 'aar')
uatImplementation (name: 'money1-release', ext: 'aar')
releaseImplementation(name: 'money2', ext: 'aar')

Should it be :

debugImplementation files('libs/money1-debug.aar')
uatImplementation files('libs/money1-release.aar')
releaseImplementation files('libs/money2.aar')

android

build.gradle

android-gradle-7.0

0 Answers

Your Answer

Accepted video resources