Important

The scripts described below are deprecated. They should be replaced with the Packager Plugin. Please refer to the Packager Plugin documentation site for more information.


DEPRECATED INFO BELOW


Custom Build Scripts

These are a set of helper methods to help set up Gradle tasks for commonly used actions. To use this in your Android Studio Gradle projects, apply this script into your module by adding:

apply from: 'https://rexmtorres.github.io/Packager/deprecated/scripts/rmt.gradle'


Available Methods

After applying the script, you will have access to the following methods described below.

exportAar

Exports the AAR and extracts the JAR (inside the AAR) into the specified location renaming the files to the specified name.

exportAar(variant, destFolder, baseFileName)
See also libraryVariants, build variants

exportApk

Exports the APK into the specified location.

exportApk(variant, destFolder, baseFileName, unsignApk)
See also applicationVariants, build variants

exportProguardMapping

Copies the Proguard map files into a specified location.

exportProguardMapping(variant, outputFolder)
See also BaseExtension, build variants, libraryVariants, applicationVariants

createJavaDoc

Generates JavaDoc with support for embedding code snippets with syntax highlighting through SyntaxHighlighter v3.0.83 from Alex Gorbatchev.

createJavaDoc(variant, additionalSourceFiles, additionalClasspathFiles, excludedFiles, javaDocTitle, javadocMemberLevel, archiveName, outputPath)

Note:
I’m thinking of deprecating this API. The original purpose of this API was to generate Javadocs w/ UML diagams generated through the yWorks UML Doclet from yWorks and have code snippets w/ syntax highlighting through SyntaxHighlighter from Alex Gorbatchev. While configuring your own Javadoc task gives you much more flexibility, setting up yWorks was a pain. And so, I created this helper function to ease the set up. Unfortunately, yWorks UML Doclet is not compatible w/ Java 8 and newer versions. So, I had to remove yWorks set up in this API. In which case, you would probably be better of configuring your own Javadoc tasks. This API still supports SyntaxHighlighter, though.


calculateLinesOfCode

Generates step count of the source code using Amateras StepCounter.

  calculateLinesOfCode(variant, outputDir, outputFile)


Usage

The methods will generate several Gradle tasks. Most of them will be categorized into the rmt group. However, the main task to take note of is the createDelivery task, and its variant-specific alternatives, which you can find under the rmtDelivery group. Simply execute the createDelivery to start assembling your module, exporting the AAR/JAR/APK files, and generating the Javadoc, step count and Proguard map files.

gradle-tasks-pane.png


Library Module Example

Below is an example of a library module using exportAar(), calculateLinesOfCode() and createJavaDoc():

apply from: 'https://rexmtorres.github.io/Packager/deprecated/scripts/rmt.gradle'

android {
    // ...

    def libName = "MyLibrary"

    libraryVariants.all { variant ->
        def flavorName = variant.flavorName
        def buildTypeName = variant.buildType.name
        def variantName = variant.name
        def variantPath = variant.dirName
        def baseJarName = "${libName}_v${defaultConfig.versionName}"
        def destFolder = "${project.rootProject.buildDir}/${libName}/${variantPath}"

        // Export the AAR and JAR files
        exportAar(variant, destFolder, baseJarName)

        // Generate step count using Amateras StepCounter
        calculateLinesOfCode(variant,
                "${project.rootProject.rootDir}/stepCounter/${project.name}/${variantPath}",
                "${libName}.csv")

        // Javadoc
        def javadocTitle = "${libName} [${buildTypeName.capitalize()}] - v${defaultConfig.versionName} API Reference"
        def archiveName = "${variantPath}/${libName}_javadoc"

        createJavaDoc(variant,
                null,                                                               // no additional sources
                files("$project.buildDir/intermediates/classes/${variantPath}"),    // add a class reference so that JavaDoc can still find the excluded classes
                ['**/R.java', '**/internal/**/*.java'],      // exclude these files
                javadocTitle, JavadocMemberLevel.PROTECTED,
                archiveName, destFolder)
    }
}


Application Module Example

Below is an example of an application module using exportApk(), calculateLinesOfCode(), exportProguardMapping() and createJavaDoc():

apply from: 'https://rexmtorres.github.io/Packager/deprecated/scripts/rmt.gradle'

android {
    // ...

    def appName = "MyApplication"

    applicationVariants.all { variant ->
        def flavorName = variant.flavorName
        def buildTypeName = variant.buildType.name
        def variantName = variant.name
        def variantPath = variant.dirName
        def baseApkName = "${appName}_v${defaultConfig.versionName}"
        def destFolder = "${project.rootProject.buildDir}/${appName}/${variantPath}"

        // Export signed and unsigned APKs
        exportApk(variant, "${destFolder}/signed/", baseApkName, false)
        exportApk(variant, "${destFolder}/unsigned/", baseApkName, true)

        // Generate step count using Amateras StepCounter
        calculateLinesOfCode(variant,
                "${project.rootProject.rootDir}/stepCounter/${project.name}/${variantPath}",
                "${appName}.csv")

        // Only obfuscated projects have Proguard maps
        if (variant.buildType.minifyEnabled) {
            exportProguardMapping(variant,
                    "${project.rootProject.rootDir.absolutePath}/proguardMap/${project.name}/${variantPath}/${baseApkName}")
        }

        // Javadoc
        def javadocTitle = "${appName} [${buildTypeName.capitalize()}] - v${defaultConfig.versionName} API Reference"
        def archiveName = "${variantPath}/${appName}_javadoc"

        createJavaDoc(variant,
                null,                                                               // no additional sources
                files("$project.buildDir/intermediates/classes/${variantPath}"),    // add a class reference so that JavaDoc can still find the excluded classes
                ['**/R.java', '**/internal/**/*.java'],      // exclude these files
                javadocTitle, JavadocMemberLevel.PROTECTED,
                archiveName, destFolder)
    }
}