1.在库项目module下的build.gradle文件中添加以下代码
apply plugin: 'com.android.library'
apply plugin: 'maven'
version = '1.0.0'
uploadArchives {
repositories {
mavenDeployer {
pom.artifactId = 'test'
repository(url: 'file://' + project.rootDir + '/outputs-aar')
}
}
}
2.在窗口的最右边打开gradle,找到相应module目录下的uploadArchives,双击开始运行
3.在控制面板中显示successful,并在项目的根目录下显示生成了一个aar的单独文件夹,表示生成成功。
生成的目录要自己配我的是这样配的
uploadArchives {
repositories {
mavenDeployer {
pom.artifactId = 'test'
repository(url: 'file://' + project.rootDir + '/outputs-aar')
}
}
}
二、导入aar
1.复制生成的.aar文件到module的libs文件夹中
2.在需要导入的module的build.gradle文件中添加以下代码:
//使用libs目录下的aar文件时需要打开该配置
repositories {
flatDir {
dirs 'libs'
}
}
3.并在dependencies{}中引用aar依赖:
compile(name: 'test-1.0.0', ext: 'aar')
4.重新构建一下。
三、查看源码
1.打开aar中的某个类,会发现无法查看源码,点击Attach Sources
2.找到aar源码的项目,导入java文件夹
3.点击确定就ok了