current position:Home>Android studio library module references AAR

Android studio library module references AAR

2022-01-26 22:25:44 Yan Long

background

Android Project import aar package , In the development process , Very common operation . An error was encountered in the project import today , Record here .

  • error message lib_diagnotic Is a component of the project model:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find :diagnotic:.
     Required by:
         project :app > project :lib_diagnotic

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
  • The reason for the error Apart from the components model engineering build.gradle In file , The following code needs to be added , stay Shell Engineering app Of build.gradle You also need to add the following code
repositories {
   flatDir {
       dirs 'libs' //this way we can find the .aar file in libs folder
       dirs '../lib_diagnotic/libs'  // model engineering ` build.gradle`  and  app The paths in the project are different , It needs to be adjusted to the corresponding aar route 
   }
}

library Module reference aar

1、 Copy aar file To engineering libs Directory

introduce aar The first step , It is necessary to put aar File copy to Corresponding to the project libs Directory

2、 Quoted in the project aar file

lib In the project build.gradle In file , add to aar File to reference

repositories {
    flatDir {
        dirs 'libs'   // aar Catalog 
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    ......
    implementation(name:'diagnotic', ext:'aar')
}

2、 Add a pair of to the main project aar File reference

app In Engineering build.gradle file , Add the following code

repositories {
    flatDir {
        dirs 'libs' //this way we can find the .aar file in libs folder
        dirs '../lib_diagnotic/libs'
    }
}

copyright notice
author[Yan Long],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262225422898.html

Random recommended