No1:
Android多项目设置
目录结构:
MyProject/
setting.gradle
app/
build.gradle
libraries/
lib1/
build.gradle
lib2/
build.gradle
setting.gradle配置文件
include ':app',':libraries:lib1',':libraries:lib2'
也可以指定项目目录
include ':example912' project(':example912').projectDir = new File(rootDir,'chapter09/example912')
No2:
库项目引用和配置
dependencies {compile project(':libraries:lib1')}
注:Android Lib打包成一个aar包,Java Lib打包成一个jar包
如果包里面有资源,就用Android Lib,如果没有并且是纯java程序可以用Java Lib
同时发布多个版本的aar包
android{ publishNonDefault true }
dependencies{ flavor1Compile project(path:':lib1',configuration:'flavor1Release') flavor2Compile project(path:':lib1',configuration:'flavor2Release') }
No3:
库项目单独发布
如何搭建自己的Maven私服:
1)使用Nexus Repository Manager,版本选择2.x.x,下载地址:http://www.sonatype.com/download-oss-sonatype,选择nexus-2.12.1-01-bundle.tar.gz包
2)在nexus-2.12.1-01injsw目录下,运行start-nexus脚本启动Nexus
3)浏览器打开http://localhost:8081/nexus/访问,Log In链接,默认用户名admin,密码admin123
No4:
build.gradle文件中应用Maven插件
apply plugin: 'com.android.library'
apply plugin: 'maven'
配置Maven构建的三要group:artifact:version
apply plugin: 'com.android.library' apply plugin: 'maven' version '1.0.0' group 'org.flysnow.widget'
uploadArchives{ repositoried{ mavenDeployer{ repository(url:"http://localhost:8081/nexus/content/repositories/releases"){ authentication(userName:"admin",password:"admin123") } snapshotRepository(url:"http://localhost:8081/nexus/content/repositories/snapshots"){ authentication(userName:"admin",password:"admin123") } pom.artifactId = "pullview" pom.packaging = "aar" } } }
告诉Gradle
buildscript{ repositoried{ jcenter() } dependencies{ classpath 'com.android.tools.build:gradle:1,5,0' } } allprojects{ repositories{ jcenter() maven{ url 'http://localhost:8081/nexus/content/groups/releases' } } }
这样就可以在依赖配置里引用刚发布的aar包
dependencies{ compile 'org.flysnow.widget:pullview:1.0.0' }