aboutsummaryrefslogtreecommitdiff
path: root/artifacts.gradle
diff options
context:
space:
mode:
Diffstat (limited to 'artifacts.gradle')
-rw-r--r--artifacts.gradle74
1 files changed, 74 insertions, 0 deletions
diff --git a/artifacts.gradle b/artifacts.gradle
index 6db3cfb..12dd3fa 100644
--- a/artifacts.gradle
+++ b/artifacts.gradle
@@ -1,3 +1,5 @@
+import groovy.xml.MarkupBuilder
+
apply plugin: 'com.github.dcendents.android-maven'
// build a jar with source files
@@ -22,4 +24,76 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
artifacts {
archives sourcesJar
archives javadocJar
+}
+
+// Task to generate our public.xml file
+// See https://developer.android.com/studio/projects/android-library.html#PrivateResources
+// We assume resources within res-public are public
+task generatepublicxml {
+
+ def resDir = project.projectDir.absolutePath + "/src/main/res-public"
+
+ def publicFolder = file(resDir + "/values")
+ if (!publicFolder.exists()) publicFolder.mkdirs()
+
+ // Include the desired res types
+ // Note: we don't need the qualified resource directories,
+ // since those resources will already be defined in the unqualified directories
+ // however, there are special cases like transition-v21 that is only available on lollipop and up
+ def tree = fileTree(dir: resDir,
+ includes: ['**/anim/*.xml',
+ '**/color/*.xml',
+ '**/drawable/*.xml',
+ '**/layout/*.xml',
+ '**/transition-v21/*.xml',
+ '**/values/*.xml'
+ ],
+ exclude: '**/public.xml'
+ );
+
+ // Create new public.xml with writer
+ new File(resDir + "/values/public.xml").withWriter { writer ->
+ // Create MarkupBuilder with 4 space indent
+ def destXml = new MarkupBuilder(new IndentPrinter(writer, " ", true));
+ def destXmlMkp = destXml.getMkp();
+
+ // GIST NOTE: our project needed the ResourceName suppression, but its not needed in general
+ destXml.resources(
+ 'xmlns:tools': 'http://schemas.android.com/tools',
+ 'tools:ignore': 'ResourceName'
+ ) {
+ // Leave file comment
+ destXmlMkp.yield "\r\n"
+ destXmlMkp.comment("AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task")
+
+ if (tree.isEmpty())
+ "public"("name": "dummy", "type": "id")
+ else
+ tree.each { resFile ->
+
+ // use the directory name to get the type
+ def type = resFile.getParentFile().getName()
+
+ if (type == "values") {
+ // Resource files under values. Parse the file, and pull out the resource definitions
+ def parsePublicResources = new XmlParser().parse(resFile)
+ parsePublicResources.children().each {
+
+ // Type is usually the element, but sometimes a type attribute is present
+ // example: <item name="line_spacing_multiplier" format="float" type="dimen">1.4</item>
+ type = it.name()
+ if (it.@type) {
+ type = it.@type
+ }
+
+ // it.@name is value in name=
+ "public"("name": it.@name, "type": type)
+ }
+ } else {
+ // Drawable, layout, etc files
+ "public"("name": resFile.getName().tokenize('.')[0], "type": type.tokenize('-')[0])
+ }
+ }
+ }
+ }
} \ No newline at end of file