android studio最新版引用项目的libs目录下的jar,arr文件

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

在这里插入图片描述

使用这种方式遇到的问题:
单独打aar包时:
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).
生成aar时不支持直接的本地.aar文件依赖项。结果AAR将被破坏,因为来自任何本地.AAR文件依赖项的类和Android资源不会打包在结果AAR中。

解决办法;
https://blog.csdn.net/yeshennet/article/details/114331818

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

-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"])
}

版权声明:本文为KindSuper_liu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。