Gradle4.0编译错误处理

最近项目升级了一下gradle,然后经常使用的./gradew assembleDebug 就报错了,报错信息是这样的

> 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). The following direct local .aar file dependencies of the :libenhance project caused this error:

解释下上面文字的意思,就是在library中使用了aar,这种情况gradle 4没办法处理,所以报错了。

解决办法一

  1. File->New module…->import .jar/.aar Package
    增加一个module,module中放置全部的aar,比如

build.gradle文件做一下修改,比如:

-configurations.maybeCreate("default")
-artifacts.add("default", file('alipaySdk-15.6.5.aar'))
-artifacts.add("default", file('xxxx1.0.3.aar'))
-artifacts.add("default", file('nnnx1.0.3.aar'))

解决方法二

在app的目录下增加libs,把aar的依赖放到里面去。比如

app/build.gradleView

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation fileTree(dir: 'libs', include: ['*.aar'])
}

libXXXX/build.gradle

dependencies{
    compileOnly fileTree(dir: "../app/libs", include: ["*.aar"])
}

小结

上述两种方法都能解决问题,方法二更好一些,因为不会报错 Cannot resolve symbol

相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页