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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
buildscript {
repositories {
maven { url '../../../../../out/repo' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.1'
}
}
apply plugin: 'android'
import com.android.builder.model.ArtifactMetaData
import com.android.builder.model.SourceProvider
// create a configuration to allow dependencies specific to the Java artifact
configurations {
foo
}
// Register an artifact type and tie it to the name "__test__".
// This name will show up in Studio. It must be unique
android.registerArtifactType("__test__", false, ArtifactMetaData.TYPE_JAVA)
// register a new SourceProvider per build type, and associate it with the artifact
// registered above.
android.buildTypes.all { type ->
project.android.registerBuildTypeSourceProvider(
"__test__", // registered name of the artifact type
type, // associate it with a BuildType
getProvider("buildType:$type.name")) // the source provider
}
// Same with ProductFlavor
android.productFlavors.all { flavor ->
project.android.registerProductFlavorSourceProvider(
"__test__", // registered name of the artifact type
flavor, // associate it with a ProductFlavor
getProvider("productFlavor:$flavor.name")) // the source provider
}
// now register a new (java) artifact for each variant, still associated
// with the artifact type registered above.
android.applicationVariants.all { variant ->
project.android.registerJavaArtifact(
"__test__", // registered name of the artifact type
variant, // associate it with a variant
"assemble:$variant.name", // name of the assemble task for this artifact
"compile:$variant.name", // name of the java compile task for this artifact
configurations.foo,
new File("classesFolder:$variant.name"), // location of the classes folder (compile output)
getProvider("provider:$variant.name")) // source provider specific to this variant for the artifact.
}
// after the artifact is created, add a dependency
dependencies {
foo files('libs/util-1.0.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
flavorDimensions "pricing", "releaseType"
productFlavors {
beta {
flavorDimension "releaseType"
}
normal {
flavorDimension "releaseType"
}
free {
flavorDimension "pricing"
}
paid {
flavorDimension "pricing"
}
}
}
public class SourceProviderImpl implements SourceProvider, Serializable {
private static final long serialVersionUID = 1L;
private final String name;
SourceProviderImpl(String name) {
this.name = name
}
String getName() {
return name
}
File getManifestFile() {
return new File(name)
}
Collection<File> getJavaDirectories() {
return Collections.emptyList()
}
Collection<File> getResourcesDirectories() {
return Collections.emptyList()
}
Collection<File> getAidlDirectories() {
return Collections.emptyList()
}
Collection<File> getRenderscriptDirectories() {
return Collections.emptyList()
}
Collection<File> getJniDirectories() {
return Collections.emptyList()
}
Collection<File> getJniLibsDirectories() {
return Collections.emptyList()
}
Collection<File> getResDirectories() {
return Collections.emptyList()
}
Collection<File> getAssetsDirectories() {
return Collections.emptyList()
}
}
SourceProvider getProvider(String name) {
return new SourceProviderImpl(name)
}
|