在项目开发时引入第三方aar包,直接run可以把app烧进手机,但是使用gradle assemble就会报错,具体报错是:
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).
之前的引入方式是
implementation files('libs/****.aar')
或者
api files('libs/****.aar')
这是因为新版本gradle,应该是7.0.2之后的版本,引入aar时使用了新的方式。
首先需要在setting.gradle中添加配置flatDir { dirs './protocol/libs','./tts/libs'}来申明本地库。
其中protocol和tts是模块名。
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
flatDir {
dirs './protocol/libs','./tts/libs' // 申明本地库
}
}
}
然后在引入aar包的module的build.gradle中添加:
implementation(name: '****', ext: 'aar')
或者
api(name: '****', ext: 'aar')
这样就可以正常assemble打包啦!