How to include aar files used in library projects in main project in Android

前端 未结 6 2106
名媛妹妹
名媛妹妹 2020-12-31 10:56

My project is including some library project. Library is using some aar files and its dependecny is already defined in the module: gradle file. I am facing problem in includ

6条回答
  •  轮回少年
    2020-12-31 11:05

    Monika Moon put me on the correct path but I don't have enough rep points to comment inline above. sigh

    So a default Android app built in 2020 with Android Studio 3.5.3 will have the following project structure via the Project View:

    --[yourAppName]
      --[app]
      --[gradle]
      build.gradle 
    

    In the top level build.gradle files add the 'flatDir' item :

    allprojects {
            repositories {
                google()
                jcenter()
    
                // needed so it picks up my aar files
                flatDir {
                    dirs 'libs'
                }
            }
    }
    

    Then in your 'app' folder shown above. You will have these two key resources:

     -- [libs] folder where you should drop your aar files
     build.gradle file that is the one you add your aar dependencies to.
    

    The default project build will already contain a 'libs' include for you but just in case your version doesn't have it this is what you need to add:

    dependencies {
        implementation fileTree(dir: './libs', include: ['*.jar'])
        implementation(name: 'fileNameBeforeExtension', ext:'aar')
    

    This is clean and works as expected.

    The AAR file I'm using is an in-house custom built for internal hardware and will never be on a public repot.

提交回复
热议问题