GRADLE-ANDROID



AGENDA



  • Build Tools.
  • Gradle Features for Android.
  • Android Studio.
  • Working on Android Studio.



BUILD TOOLS

BUILD TOOLS


Build automation is the act of scripting or automating a wide variety of tasks that software developers do in their day-to-day activities including things like:

  • compiling computer source code  into binary code.
  • packaging binary code.
  • running tests.
  • deployment to production systems.
  • creating documentation and/or release notes.


       

    Popular Build Tools


    • Apache Ant popular for Java platform development and uses an XML file format.                                                                                                         

    • Apache Maven a Java platform tool for project management and automated software build.                                                                            

    • Gradle an open-source build and automation system with a Groovy Rake Domain Specific Language (DSL).
       

    Apache Ant



    • First "Modern Build Tool".
    • Kind of like "Make". 
    • Implemented in Java and used mostly for Java projects. 
    • First public release was in 2000 and most popular build tool for Java projects.
     

    Apache maven


    • First released in 2004.
    •  Introduced project structure conventions, dependency management and a central artifact repository, Maven Central.
    • Uses XML for writing a build file (pom.xml). 
    • Developers just have to describe the structure of the project (if it differentiates from the conventions) .
    • Capable of downloading dependencies through a network.

    Gradle



    • Gradle is the youngest build tool of the three.
    • It is a combiation of  Ant’s power and flexibility with Maven’s dependency management and conventions.
    • Gradle v1.0 was released in 2012.
    •  XML is not used anymore–instead, Domain Specific Language (DSL) based on the JVM language Groovy.
    • No more verbosity of XML.
    • More simple and clear statements. 

    Comparison

    Gradle - Highlights


    Google selected Gradle as the foundation of the Android SDK build system because,

    • It provides flexibility .
    • ability to define common standards for Android builds. 
    • simple, declarative DSL to configure Gradle builds.
    • a single, authoritative build that powers both the Android Studio IDE and builds from the command-line.  


    GRADLE FEATURES FOR ANDROID

    GRADLE FEATURES FOR ANDROID

    Product Flavors - Many mobile applications have a free version and a paid version while other applications may ship seasonal variations. With Gradle product flavors are easy to manage with a few lines of code.


    Build Type -   Build types control application packaging and build configuration for different types of debug and release builds.


    Build Variants - Combination of BuildTypes and Flavors.


    continued...


    Signing Configuration - The Gradle Android DSL provides a very simple way to customize keystores and signing configuration across different build types.


    Dependency Management - Gradle offers a flexible approach to dependency management that can reuse existing Maven repositories or reference local JARs.  If you depend on libraries from Central or if you run your own local repositories, Gradle can adapt to any requirement.


      continued...


      Testing - The Gradle-based Android build system bring a new focus on testing. With Gradle you can run unit and integration tests without creating subprojects. Gradle supports several scenarios for integration testing on build servers.

      Test Server API supports Hosted Testing - Integration with Jenkins-based build servers and services from AppThwackTestDroid, and Manymo means that your build can support complex, massively-parallel integration testing scenarios.



      ANDROID STUDIO

      ANDROID STUDIO

      Android Studio is an integrated development environment (IDE) for the Android platform. It was announced on 16 May 2013 at the Google I/O conference by Google.


      Latest Android Studio Canary Build: 0.9.3 released on Nov 14, 2014 and  Developer Build: 0.8.9 released  on Sep 03, 2014



      Project Structure

      The basic project starts with two components called “source sets”. 

      • src/main/                       ------------------>main source code
      • src/androidTest/     ------------------>test code

      Inside each of these folders,

      For both the Java and Android plugin, the location of the Java source code and the Java resources:

      • java/                    ---------------------> source code 
      • resources/      ---------------------> resources


      continued...

      Extra files and folders specific to Android:

      • AndroidManifest.xml
      • res/
      • assets/
      • aidl/
      • rs/
      • jni/


      Default Configurations

      Example:

      Properties:

      SourceSets

      To replace the default source folders, you will want to use srcDirs 

      Here’s an example, using the old project structure for the main code and remapping the androidTest sourceSet to the tests folder:


      Signing Configurations

      Signing an application requires the following:

      • A keystore , A keystore password, A key alias name, A key password, The store type
      Example:


      Build Types

      Default - debug and a release versions.

      Properties:

      Adding Library Project


      Project Structure:




      continued....

      settings.gradle:

      include ':app', ':libraries:lib1', ':libraries:lib2'


      build.gradle:






      Creating a Library Project

      build.gradle:



      • A Library project's main output is an .aar package .
      • They have build types and product flavors, and can potentially generate more than one version of the aar.



      Testing

      • Integrated into the application project. No need for a separate test project anymore.


      • Next to the main sourceSet is the androidTest sourceSet, located by default in src/androidTest/


      There are a few values that can be configured for the test app:

      • testPackageName
      • testInstrumentationRunner
      • testHandlingProfiling
      • testFunctionalTest


      continued...

      default config:


      • Test results are stored as XML files at build/androidTest-results  and html reports at  

        build/reports/androidTests

        .
      • This can be configured as,


      Build Variants

      Enables creating different versions of the same application.


      Use cases:

      1. Different versions of the same application - a free/demo version vs the “pro” paid application.
      2. Same application packaged differently for multi-apk in Google Play Store.
      3. A combination of 1. and 2.


      Product Flavors

      Defines a customized version of the application.

      Configuration:


       

      continued...

      This creates four sourceSets:

      • android.sourceSets.flavor1
        • Location src/flavor2/
      • Android.sourceSets.flavor2
        • Location src/flavor2/
      • Android.sourceSets.androidTestFlavor1
        • Location src/androidTestFlavor1/
      • android.sourceSets.androidTestFlavor2
        • Location src/androidTestFlavor2/   

      Dependencies:
      Each Flavor can have its own dependancies as:


      WORKING ON ANDROID STUDIO

      Tasks


      • Import an Eclipse Project.
      • Import project from Git repository.
      • Add libraries to existing project.
      • Create a project in Studio.
      • Add BuildTypes, Flavors.
      • Add testing including flavors.
      • Eclipse plugin .

      Version Control System

      Integration with VCS like Git, CVS,Mercurial...

      .gitignore:

      .gradle
      /local.properties
      /.idea/workspace.xml
      /.idea/tasks.xml
      .DS_Store


      Command line 

      • ./gradlew clean
      • ./gradlew build
      • ./gradlew buildRelease
      • ./gradlew debug


      adb shell commands:

      • adb install C:\Users\Name\MyProject\build\Jorgesys.apk
      • adb shell am start -n com.package.name/com.package.name.ActivityName




      ?

      References






      Thank You

      Gradle-android

      By Torry Harris Business Solutions

      Gradle-android

      This gives a basic idea about Gradle - build tool, its features and usage in Android Studio IDE

      • 1,506