Build your Android App with Gradle Android new
Build your Android App with Gradle Android new build system
Agenda • • What is Gradle Getting started with gradle Use cases Q&A
Download Meetup Sample Code – http: //goo. gl/qo. XAfa
What is gradle • Gradle is a JVM based project build automation tool that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy based domain-specific-language (DSL) instead of the more traditional XML form of declaring the project configuration.
Installation • Download the latest android plugin supported Gradle version • Extract the downloaded zip “gradle-1. 10 -all. zip” to any directory • Configure the GRADLE_HOME environment variable • set GRADLE_HOME=<installed directoy>gradle-1. 10 • set PATH=%PATH%%GRADLE_HOME%bin • C: > gradle
Gradle Task • C: > gradle tasks • Applying the plugin’s to the build file will automatically add set of build task to run • assemble The task to assemble the output(s) of the project • check The task to run all the checks. • build This task does both assemble and check • clean This task cleans the output of the project
Build File Skeleton buildscript { repositories { maven. Central() } dependencies { classpath 'com. android. tools. build: gradle: 0. 8. +' } } apply plugin: 'android' android { build. Tools. Version "19. 0. 1" compile. Sdk. Version 19 }
Gradle Wrapper task wrapper(type: Wrapper) { gradle. Version = '1. 10‘ } • C: > gradle wrapper / └── gradlew. bat └── gradle └── wrapper └── gradle-wrapper. jar └── gradle-wrapper. properties
Convention Over Configuration src └── main l └── java l └── instrument. Test └── java source. Sets { main{ manifest. src. File 'Android. Manifest. xml' java. src. Dirs = ['src'] resources. src. Dirs = ['src'] res. src. Dirs = ['res'] assets. src. Dirs = ['assets'] } instrument. Test. set. Root('tests') }
Usecase : 1 I have project with multiple library projects, one of which is required to be shared with one of my colleague who's working in a another project.
Dependency Management • dependencies DSL element is part of the standard Gradle • Can add dependencies on local and remote libraries • To add a dependency have to provide library on the compile configuration under dependencies DSL • Everything added to the compile configuration get packaged in to the final APK • Gradle will follow all dependencies transitively
Dependencies On Multiple Projects • Each projects will have its own build. gradle declaring how it gets built • There will be a file called settings. gradle at the root, which define which folder is a Gradle project • If there are more than one library, importing order should be considered on dependencies on each other
Publish Library To Artifact Repo • Publish artifacts to local artifact repository Proper release and snapshot release management Maven Central
Usecase : 2 • I want to make a digitally signed and secured release version of my app
Build types • This is achieved by build. Types DSL • By default, the android plugin automatically sets up the project to build both a debug and a release version of the application • Difference is that the ability to enable debug and how the APK is signed • It allows to customize both debug and release versions, as well as creating other build types
Build Types… • Build Types can contribute to the build with code and resources. • For each Build Type, a new matching source. Set is created, under src directory src/<buildtypename>/ • This means the Build Type names cannot be main or instrument. Test
Signing APK • Android system will not install or run an application that is not signed appropriately. • To sign an APK have to make use of signing. Configs DSL
Obfuscating • Tool Pro. Guard is used automatically to obfuscate the APK • It will rename classes, fields, and methods with semantically obscure names to make it difficult to reverse engineer. • Android plugin support proguard version is 4. 10 • Pro. Guard will shrinks, optimizes, and remove unused code which will result smaller APK
Usecase : 3 • I want to make a free version of my application with less features and commercial version with all features.
Build Variants – Different versions of the same application or Same application packaged differently or combination of both. • Have to occupy product. Flavors DSL • Build Type + Product Flavor = Build Variant • Product flavor will generate APK’s for all possible combinations of Build Types and Product Flavors Debug Release Free-Debug Free-Release Commercial-Debug Commercial-Release
Usecase : 4 I want to unit test my project with a testing framework,
Testing • No need to have a separate test project any more it is integrated to the application project • Default location for the instrument test cases are located in src/instrument. Test • Test APK is built to test the app under test using the Android instrumentation framework • No need to have a Android. Manifest. xml for the app, cause it will get generated automatically • Test app manifest is automatically get filled with the package name and the instrument test runner
Usecase : 5 • I want to measure the quality of my source code continuously with some quality tools by Integrate it with a Continuous Integration System
Q&A
Thank you
- Slides: 25