本文通过Android Studio创建一个Android Library项目,然后发布到本地的Maven仓库。
1.创建Android Library模块
2.配置build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
apply plugin: 'com.android.library'
apply plugin: 'maven'
android { compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile( 'proguard-android.txt' ), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
} dependencies { compile fileTree(dir: 'libs' , include: [ '*.jar' ])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.3'
} uploadArchives { repositories {
mavenDeployer {
repository(url: 'maven.repo.local' )
pom.project {
name 'viewlibrary'
groupId 'secondriver'
artifactId 'viewlibrary'
version '1.0.0'
packaging 'aar'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'secondriver'
name 'secondriver'
}
}
}
}
}
} |
3. 执行gradle task发布android Library
1
2
3
4
5
6
7
|
>set JAVA_HOME=D:\__dev\Java\jdk1. 8 .0_60
>gradle upload :viewlibrary:uploadArchives BUILD SUCCESSFUL Total time: 36.351 secs
|
由于本地默认的JDK是1.6,在执行gradle的时候指定JDK。
发布成功后可以USER_HOME/.m2/setting.xml中指定的在本地仓库目录
secondriver\viewlibrary\1.0.0中看到viewlibrary-1.0.0.aar文件。
4. 在Android App模块中引用依赖该类库
build.gradle文件中配置:
1
2
3
4
5
|
repositories { mavenLocal()
mavenCentral()
jcenter()
}
|
1
2
3
4
|
dependencies { compile fileTree(dir: 'libs' , include: [ '*.jar' ])
compile 'secondriver:viewlibrary:1.0.0@aar'
} |
本文转自 secondriver 51CTO博客,原文链接:http://blog.51cto.com/aiilive/1716808,如需转载请自行联系原作者