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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// ATTENTION -- hash value of this file is checked in the corresponding
// integration test. Please make sure any changes you make here are
// backwards compatible.
apply from: "../commonHeader.gradle"
buildscript { apply from: "../commonBuildScript.gradle" }
apply plugin: 'com.android.application'
import com.android.annotations.NonNull
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
[], // generated source folders
[], // tasks to generate sources etc. in the IDE.
configurations.foo,
new File("classesFolder:$variant.name"), // location of the classes folder (compile output)
new File("resources:$variant.name"), // location of the resources folder
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 rootProject.latestCompileSdk
buildToolsVersion = rootProject.buildToolsVersion
flavorDimensions "pricing", "releaseType"
productFlavors {
beta {
dimension "releaseType"
}
normal {
dimension "releaseType"
}
free {
dimension "pricing"
}
paid {
dimension "pricing"
}
}
}
public class SourceProviderImpl implements SourceProvider, Serializable {
private static final long serialVersionUID = 1L;
private final String name;
SourceProviderImpl(String name) {
this.name = name
}
@NonNull
String getName() {
return name
}
@NonNull
File getManifestFile() {
return new File(name)
}
@NonNull
Collection<File> getJavaDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getResourcesDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getAidlDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getRenderscriptDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getCDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getCppDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getJniLibsDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getResDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getAssetsDirectories() {
return Collections.emptyList()
}
@NonNull
Collection<File> getShadersDirectories() {
return Collections.emptyList()
}
}
SourceProvider getProvider(String name) {
return new SourceProviderImpl(name)
}
|