- 1. 把 AAR 放入 libs
- 2. 在 build.gradle 添加 repositories{flatDir{dirs ‘libs’}}
- 3. 在 build.gradle 添加 dependencies{compile(name:’nameOfYourAARFile’, ext:’aar’)}
其中当某个本地 aar/jar 需要在多个 module 进行依赖时,按照官方本身做法
Handling transitive dependencies for local artifacts (jars and aar) If you have a local jar or aar library that you want to use in more than one project, you cannot just reference it directly as a local dependency. This is because the android plugin will complain if it finds the same jar file twice when dexing the project and all its dependencies. (Note that right now you can't actually use a local aar file even if you only reference it once). One way to fix this is to deploy the artifact in a repository. While it's possible, it might not be convenient due to the overhead of managing such a repository. Another option is to create a new Gradle sub-project, and to make this project's published artifact be the jar or aar file that you want to reuse. Then you can simply have other Gradle sub-projects depend on this new sub-project. In this new sub-project, simply create a build.gradle with the following: configurations.create("default") artifacts.add("default", file('somelib.jar'))
经过实际测试,创建一个放有依赖库的 Module,里面包含所要的依赖库,和 build.gradele 文件
例如:当前 Module 名称为:ShareLibs configurations.create("default") artifacts.add("default", file('libs/somelib.jar')) 然后把此 Module 添加到根目录的 settings.gradle 中 'sharelibs' 其他各个 Module 都可以使用 implementation project(':sharelibs')
发表回复