build.gradle


Overview

The `build.gradle` file is a Gradle build configuration script for an **Android library module**. It manages the build lifecycle, dependencies, versioning, and publishing configurations of the `tubi-player` library, which is a media streaming video player built on top of Google's ExoPlayer.

This file applies necessary Gradle plugins, defines Android SDK versions, configures build types, sets up dependencies, and configures the Bintray release plugin to enable easy artifact publishing. It also customizes output artifact naming and configures Java compatibility and testing options.


Detailed Explanation

Plugins

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release' // applied after artifact generating plugins

Buildscript Configuration

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.novoda:bintray-release:0.8.0'
    }
}

Repositories

repositories {
    flatDir {
        dirs 'libs'
    }
}

Version Definition

def libVersion = "v2.2"

Android Configuration Block

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    dataBinding {
        enabled = true
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName libVersion

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    libraryVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = "tubiplayer-${libVersion}.aar"
        }
    }
}

Dependencies

dependencies {
    def supportLibraryVersion = '27.1.1'
    def playServiceVersion = '16.0.3'

    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v13'
    }

    api fileTree(dir: 'libs', include: ['*.jar'])

    api(name: 'vaud-text-view-0.0.2', ext: 'aar')
    api(name: 'tubi-loading-view-0.0.5', ext: 'aar')

    api 'com.afollestad.material-dialogs:core:0.9.4.5'
    api 'com.squareup.picasso:picasso:2.5.2'

    api 'com.google.android.exoplayer:exoplayer:2.8.4'
    api "com.android.support:appcompat-v7:${supportLibraryVersion}"
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api "com.android.support:design:${supportLibraryVersion}"

    // Chromecast support
    api "com.android.support:mediarouter-v7:${supportLibraryVersion}"
    api "com.google.android.gms:play-services-cast-framework:${playServiceVersion}"

    // Dagger 2 dependency injection
    api "com.google.dagger:dagger:2.9"
    annotationProcessor "com.google.dagger:dagger-compiler:2.9"
    compileOnly 'javax.annotation:jsr250-api:1.0'

    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    api "android.arch.lifecycle:runtime:1.0.3"

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
}

Publishing Configuration

publish {
    userOrg = 'tubitv'
    repoName = 'Media'
    groupId = 'com.tubitv.media'
    artifactId = 'tubi-player'
    publishVersion = libVersion
    licences = ['MIT']
    desc = 'A media streaming video player based on ExoPlayer from google, with convenience methods for ad supported content'
    website = 'https://github.com/Tubitv/TubiPlayer'

    // Uncomment and configure for real publishing
    // dryRun = true
    // bintrayUser = properties.getProperty("bintray.user")
    // bintrayKey = properties.getProperty("bintray.apikey")
}

Important Implementation Details


Interaction With Other Parts of the System


Usage Examples

Building the Library

Run the following command to build the `.aar` artifact:

./gradlew clean assembleRelease

This produces an `.aar` named `tubiplayer-v2.2.aar` under `build/outputs/aar/`.


Publishing the Library

After setting your Bintray credentials, publish to Bintray with:

./gradlew bintrayUpload -PbintrayUser=yourUser -PbintrayKey=yourApiKey

Add `-PdryRun=false` to actually upload rather than simulate.


Visual Diagram

flowchart TD
    A[build.gradle] --> B[Apply Plugins]
    B --> C[Android Library Plugin]
    B --> D[Bintray Release Plugin]

    A --> E[Buildscript]
    E --> F[Repositories: jcenter, google]
    E --> G[Classpath: bintray-release]

    A --> H[Repositories]
    H --> I[Local flatDir 'libs']

    A --> J[Android Configuration]
    J --> K[SDK & Build Tools Versions]
    J --> L[Data Binding Enabled]
    J --> M[Unit Test Options]
    J --> N[Default Config: minSdkVersion, targetSdkVersion, versionName]
    J --> O[Build Types: release, debug]
    J --> P[Java 8 Compatibility]
    J --> Q[Output Filename Customization]

    A --> R[Dependencies]
    R --> S[Local AARs]
    R --> T[Android Support Libraries]
    R --> U[ExoPlayer, Chromecast]
    R --> V[Dagger 2]
    R --> W[Testing Frameworks]

    A --> X[Publishing Configuration]
    X --> Y[Bintray Metadata]
    X --> Z[Credentials (commented)]

Summary

This `build.gradle` file is a well-structured Gradle build script tailored for an Android library project that provides a media player. It configures Android build parameters, manages dependencies including local and remote libraries, integrates testing frameworks, customizes output artifacts, and configures automated publishing to Bintray. The file ensures the library is built consistently and can be shared efficiently across different projects within the Tubi ecosystem.