最近升级了最新的AndroidStdio版本,然后导入之前的安卓工程

Direct local .aar file dependencies are not supported when building an AAR.插图

然后经过一番折腾后项目可以跑了,但是意外发现出release包的时候报错了,

Direct local .aar file dependencies are not supported when building an AAR.

网上有很多解决方法,但是我觉得写的不是很详细,在这里再简单的记录一下。

原因:Android studio版本高,Android插件版本高。子module中依赖了aar包,由于我的项目是组件化项目,子module依赖aar包是必然的。传递依赖也会有问题,例如 a.aar->module A->module B,就算module B依赖了module A,module A依赖了a.aar,这时候依旧会出问题正确的办法是要a.aar->module B 且 a.aar->module A,即无论moduleA moduleB都依赖a.aar。

解决方法:将引入的aar包变成一个module,让其他需要的模块可以随时引用,这样的好处在于,不需要将aar包复制来复制去,每个module都copy一份到libs中。也不会出现重复依赖的问题。

下面就写一下我的解决步骤:

1.在项目根目录下面新建一个文件夹 supportBaseLib,然后将aar文件移动到这个文件夹下面,有多少个aar就新建多少个文件夹。

Direct local .aar file dependencies are not supported when building an AAR.插图(1)

2.新建build.gradle文件在supportBaseLib中,文件中的内容如下:

configurations.maybeCreate("default")
artifacts.add("default", file('support_autolayout-release.aar'))
工程结构如图:

support_autolayout-release.aar 这个名字改成自己的aar的名字就好了

3.在settings.gradle中将每一个aar包的module都写进去(这一步很重要,否则Android studio识别不了你写的module,相当于注册你写的module,不要忘了这一步)

Direct local .aar file dependencies are not supported when building an AAR.插图(2)

4.在你需要的模块中引入你的新module(每一个需要的模块    都需要引入,要不然会报找不到xxx.aar)

Direct local .aar file dependencies are not supported when building an AAR.插图(3)

Direct local .aar file dependencies are not supported when building an AAR.插图(4)

我的项目中有2处用到,所以添加了2个地方,这个根据自己的来。

这样重新配置好了,重新clean\build一下,如果没有报错的话就是好了。

编译之后supportBaseLib目录下面就会有build文件夹,里面的东西时编译文件,不用管了,能出release包,到手机上安装一下,没有问题。

本站无任何商业行为
个人在线分享 » Direct local .aar file dependencies are not supported when building an AAR.
E-->