1 / 25

Build your Android App with Gradle

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/qoXAfa. What is gradle.

brant
Download Presentation

Build your Android App with Gradle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Build your Android App with Gradle Android new build system

  2. Agenda • What is Gradle • Getting started with gradle • Use cases • Q&A

  3. Download Meetup Sample Code • http://goo.gl/qoXAfa

  4. 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 baseddomain-specific-language (DSL) instead of the more traditional XML form of declaring the project configuration.

  5. 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

  6. Gradle Task • C:\> gradle tasks • Applying the plugin’s to the build file will automatically add set of build task to run • assembleThe task to assemble the output(s) of the project • checkThe task to run all the checks. • buildThis task does both assemble and check • cleanThis task cleans the output of the project

  7. Build File Skeleton buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.8.+' } } apply plugin: 'android' android { buildToolsVersion "19.0.1" compileSdkVersion 19 }

  8. Gradle Wrapper task wrapper(type: Wrapper) { gradleVersion= '1.10‘ } • C:\> gradle wrapper / └── gradlew └── gradlew.bat └── gradle └── wrapper └── gradle-wrapper.jar └── gradle-wrapper.properties

  9. Convention Over Configuration src └── main l └── java l └── instrumentTest └── java sourceSets { main{ manifest.srcFile'AndroidManifest.xml' java.srcDirs= ['src'] resources.srcDirs= ['src'] res.srcDirs= ['res'] assets.srcDirs= ['assets'] } instrumentTest.setRoot('tests') }

  10. 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.

  11. 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 compileconfiguration get packaged in to the final APK • Gradle will follow all dependencies transitively

  12. Dependencies On Multiple Projects • Each projects will have its own build.gradle declaring how it gets built • There will be a file calledsettings.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

  13. Publish Library To Artifact Repo • Publish artifacts to local artifact repository • Proper release and snapshot release management Maven Central

  14. Usecase :2 • I want to make a digitally signed and secured release version of my app

  15. Build types • This is achieved by buildTypesDSL • 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

  16. Build Types… • Build Types can contribute to the build with code and resources. • For each Build Type, a new matching sourceSetis created, under src directory src/<buildtypename>/ • This means the Build Type names cannot be main or instrumentTest

  17. 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 signingConfigsDSL

  18. Obfuscating • Tool ProGuard 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 • ProGuardwill shrinks, optimizes, and remove unused code which will result smaller APK

  19. Usecase : 3 • I want to make a free version of my application with less features and commercial version with all features.

  20. Build Variants • Different versions of the same application or Same application packaged differently or combination of both. • Have to occupy productFlavors DSL • Build Type + Product Flavor = Build Variant • Product flavor will generate APK’s for all possible combinations of Build Types and Product Flavors

  21. Usecase: 4 I want to unit test my project with a testing framework,

  22. 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/instrumentTest • Test APK is built to test the app under test using the Android instrumentation framework • No need to have a AndroidManifest.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

  23. 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

  24. Q&A

  25. Thank you

More Related