SlideShare a Scribd company logo
The new build system for Android
Overview
• Gradle basics
• Gradle Plugins
• Gradle and Studio
• Demos
• Gradle 与TV版
• Resources
What’s Gradle?
1. https://gradle.org
2. https://en.wikipedia.org/wiki/Gradle
• Gradle is an open source build automation system.
• Grade introduces DSL instead of the more traditional XML
form of declaring the project configuration.
• focused around Java, Groovy and Scala development and
deployment, but more languages and project workflows are
on the roadmap.
• Gradle can automate the building, testing, publishing,
deployment.
Why Gradle?
1. Why Gradle?
2. Why choose Gradle?
• create custom build logic through plugins.
• dependency management
• Plugins can expose their own DSL and their own API for
build files to use.
• Gradle combines the best features from other build tools.
Installing Gradle
1. gradle installation
• requires a Java JDK or JRE to be installed, version 6 or higher
• Gradle ships with its own Groovy library, therefore Groovy does
not need to be installed.
• Any existing Groovy installation is ignored by Gradle.
• Gradle uses whatever JDK it finds in your path
• download (http://gradle.org/downloads)
• unpacking
• add GRADLE_HOME/bin to your PATH environment variable
• Android Studio Project includes grade
Groovy
1. http://learnxinyminutes.com/docs/groovy/
• http://groovy-lang.org/
• The language used by Gradle
• Great similarity to Java
• builds upon the strengths of Java but has additional power features
inspired by languages like Python, Ruby and Smalltalk
Build Script Basics
1. http://rominirani.com/2014/07/28/gradle-tutorial-part-1-installation-setup/
2. https://gradle.org/docs/current/userguide/tutorial_using_tasks.html#N101A9
• Project
What a project represents depends on what it is that you are doing with Gradle
• Task
A task represents some atomic piece of work which a build performs.This might be compiling some
classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.
• Plugin
A plugin is a mechanism by which we can extend the capabilities of Gradle .
Demo
1. http://rominirani.com/2014/07/28/gradle-tutorial-part-1-installation-setup/
//defaultTasks 'buildTask'
task compileTask << {
System.out.println "compiling..."
}
task buildTask << {
//task buildTask (dependsOn:compileTask) << {
System.out.println "building..."
}
build.gradle
2.Gradle Plugin
• Gradle plugin for Java
• Gradle plugin for Android
• for eclipse,idea,findbugs,c,cpp,oc,jetty……
1. https://gradle.org/docs/current/userguide/plugins.html
2. https://gradle.org/docs/current/userguide/standard_plugins.html
Gradle Plugin for Java
• Source sets
• Tasks
• Project layout
• Dependency management
• ···
1. http://gradle.org/docs/current/userguide/java_plugin.html
Demo
1. http://rominirani.com/2014/07/28/gradle-tutorial-part-2-java-projects/
apply plugin: ‘java' // packaged with grade
archivesBaseName = "quote"
version = '1.0-FINAL'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
build.gradle
Gradle Plugin for Android
1. http://tools.android.com/tech-docs/new-build-system/user-guide
2. https://www.youtube.com/watch?v=LCJAgPkpmR0
3. http://tools.android.com/build
• Published in May, 2013
• 1.0 Released in Dec, 2014
• git clone
https://android.googlesource.com/platform/prebuilts/gr
adle-plugin
Goals of the new build system
• Make it easy to reuse code and resources
• Make it easy to create several variants of an
application, either for multi-apk distribution or for
different flavors of an application
• Make it easy to configure, extend and customize
the build process
• Good IDE integration
1. http://tools.android.com/tech-docs/new-build-system/user-guide
Android Plugin DSL Reference
1. Android Plugin DSL Reference
defaultConfig{}
signingConfigs{}
productFlavors{}
buildTypes{} BuildType
ProductFlavor
signingConfig
LintOptions
……{}
Blocks DSL types
signing Configs
• configuration of how an application is signed
• what can be customised?
• keyAlias
• keyPassword
• storeFile
• storePassword
• storeType
• hide key password
1. http://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file-
using-gradle
Product Flavors
• A product flavor defines a customized version of
the application build by the project. A single project
can have different flavors which change the
generated application
• This new concept is designed to help when the
differences are very, very minimum
• Although different flavors could be very different
applications, using Library Projects is a better use
case for this, and the build system still supports
this.
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
What can be customised by Product
Flavor?
• minSdkVersion
• targetSdkVersion
• versionCode
• versionName
• package name
(overrides value from
manifest)
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
• release signing info (keystore,
key alias, passwords,…)
• BuildConfig: Ability to provide
custom Java code
• NDK ABI filter (Not implemented
yet)
• Additionally, Product Flavor can
provide their own source code,
resources and manifest.
Build Types
• A build type allows configuration of how an application is
packaged for debugging or release purpose.
• This concept is not meant to be used to create different versions
of the same application. This is orthogonal to Product Flavor.
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
What can be customised by Build Types?
• manifest debuggable flag
• native compilation debug flag
• proguard enabled + specific rules
• debug signing flag (ie whether to use debug key or release key)
• package name suffix (2)
• Buildconfig
• DEBUG flag. Set automatically based on the manifest debuggable
flag.
• Ability to provide custom Java code.
• Types "Release" and "Debug" are automatically created and can
be reconfigured
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
Build Variants
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
• Build Type + Product Flavor = Build Variant
type1 type2
flavor1 flavor1-type1 flavor1-type2
flavor2 flavor2-type1 flavor2-type2
Sourcesets
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
• remap src structure
• eclipse compatibility
Dependencies
• Simply include any artifacts provided by mavenCentral()
…
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.jpardogo.flabbylistview:library:+'
compile 'com.jpardogo.googleprogressbar:library:+'
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.umeng.analytics:analytics:5.2.4'
}
…
build.gradle
Dependencies
• 指定你自己的仓库地址
…
repositories {
maven {
url "http://repo.mycompany.com/repo"
}
}
…
build.gradle
• 常见的maven仓库
• http://search.maven.org (mavenCentral())
• https://bintray.com/bintray/jcenter (jcenter())
• http://maven.oschina.net/home.html
• ( maven{ url 'http://maven.oschina.net/content/groups/public/'} )
Multi Project Build (Library Projects)
1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
• use the settings.gradle files to declare library projects
• add library projects as "compile" dependency
• 自定义library project位置
…
include ':letvCore'
include ':loginLib'
include ':letv'
project(':letvCore').projectDir = new File(rootDir, "../librarys/letvCore")
project(':loginLib').projectDir = new File(rootDir, "../librarys/loginLib")
…
settings.gradle
Demo
• 如何通过一套代码开发不同功能的apk
• git clone https://github.com/ghuiii/gradledemo.git
代码合并规则
• 图片、音频、 XML 类型的 Drawable 等资源文件,将会进行文件级的覆盖
• 字符串、颜色值、整型等资源以及 AndroidManifest.xml ,将会进行元素级
的覆盖
• 代码资源,同一个类, buildTypes 、 productFlavors 、 main 中只能存在
一次,否则会有类重复的错误
• 覆盖等级为:buildTypes > productFlavors > main
1. http://ask.android-studio.org/?/article/30
Gradle plugin for android 常见task
1. http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Tasks
Studio&Gradle
1. http://developer.android.com/tools/building/index.html
• Good IDE integration
• The IDE doesn’t do a build anymore
• Building and Running from Android Studio
• Building and Running from Command Line
Gradle 与 tv版
从maven仓库获取依赖的好处
1. 将主工程与依赖隔离开,方便对依赖的管理,它们之间只是通过一条gradle语句建
立联系
2. 依赖不再会进入主工程的代码仓库
3. 在本地不会存在依赖的重复副本(依赖只会缓存一份到本地)
Resources
• http://gradle.org/docs/current/userguide/userguide.html
• http://rominirani.com/2014/07/28/gradle-tutorial-series-an-
overview/
• http://avatarqing.github.io/Gradle-Plugin-User-Guide-Chinese-
Verision/introduction/README.html
• http://developer.android.com/sdk/installing/studio-build.html
• http://apdr.qiniudn.com/index.html
Thanks
Ad

More Related Content

What's hot (20)

Threading in C#
Threading in C#Threading in C#
Threading in C#
Medhat Dawoud
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
Dmitry Buzdin
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
Sangeeta Ashrit
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
Emprovise
 
Flutter
FlutterFlutter
Flutter
Himanshu Singh
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
Luong Vo
 
Introduction to Apache Hadoop
Introduction to Apache HadoopIntroduction to Apache Hadoop
Introduction to Apache Hadoop
Christopher Pezza
 
Why Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) ModelWhy Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) Model
Dean Wampler
 
ADO.NET
ADO.NETADO.NET
ADO.NET
Wani Zahoor
 
Android presentation - Gradle ++
Android presentation - Gradle ++Android presentation - Gradle ++
Android presentation - Gradle ++
Javier de Pedro López
 
Flutter technology Based on Web Development
Flutter technology Based on Web Development Flutter technology Based on Web Development
Flutter technology Based on Web Development
divyawani2
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
nationalmobileapps
 
Introduction to High-Performance Computing (HPC) Containers and Singularity*
Introduction to High-Performance Computing (HPC) Containers and Singularity*Introduction to High-Performance Computing (HPC) Containers and Singularity*
Introduction to High-Performance Computing (HPC) Containers and Singularity*
Intel® Software
 
CI-CD WITH GITLAB WORKFLOW
CI-CD WITH GITLAB WORKFLOWCI-CD WITH GITLAB WORKFLOW
CI-CD WITH GITLAB WORKFLOW
AddWeb Solution Pvt. Ltd.
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
CodeAndroid
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
David Gómez García
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
 
Flutter for web
Flutter for webFlutter for web
Flutter for web
rihannakedy
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
Emprovise
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
Luong Vo
 
Introduction to Apache Hadoop
Introduction to Apache HadoopIntroduction to Apache Hadoop
Introduction to Apache Hadoop
Christopher Pezza
 
Why Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) ModelWhy Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) Model
Dean Wampler
 
Flutter technology Based on Web Development
Flutter technology Based on Web Development Flutter technology Based on Web Development
Flutter technology Based on Web Development
divyawani2
 
Introduction to High-Performance Computing (HPC) Containers and Singularity*
Introduction to High-Performance Computing (HPC) Containers and Singularity*Introduction to High-Performance Computing (HPC) Containers and Singularity*
Introduction to High-Performance Computing (HPC) Containers and Singularity*
Intel® Software
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
CodeAndroid
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
David Gómez García
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 

Viewers also liked (20)

簡單上手Android studio
簡單上手Android studio簡單上手Android studio
簡單上手Android studio
琨堯 林
 
Android gradle 从入门到gg 0
Android gradle 从入门到gg 0Android gradle 从入门到gg 0
Android gradle 从入门到gg 0
Jun Liu
 
Android - Background operation
Android - Background operationAndroid - Background operation
Android - Background operation
Matteo Bonifazi
 
Android Fundamentals - Day 2
Android Fundamentals - Day 2Android Fundamentals - Day 2
Android Fundamentals - Day 2
Mohammad Tarek
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
Amr Salman
 
Android Fundamentals
Android FundamentalsAndroid Fundamentals
Android Fundamentals
Mohammad Tarek
 
Introduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding libraryIntroduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding library
Kaushal Dhruw
 
Gradle for Android Developers
Gradle for Android DevelopersGradle for Android Developers
Gradle for Android Developers
Josiah Renaudin
 
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
Deepu S Nath
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
Kevin He
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & Beyond
Kaushal Dhruw
 
Gradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionGradle & Android Studio - Introduction
Gradle & Android Studio - Introduction
Kevin Pelgrims
 
Android Application Fundamentals
Android Application FundamentalsAndroid Application Fundamentals
Android Application Fundamentals
Vikalp Jain
 
作業系統
作業系統作業系統
作業系統
雅茵 許
 
New to android studio
New to android studioNew to android studio
New to android studio
Engine Bai
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
Ahsanul Karim
 
A Deep Dive into Open Source Android Development
A Deep Dive into Open Source Android DevelopmentA Deep Dive into Open Source Android Development
A Deep Dive into Open Source Android Development
David Wu
 
Android things intro
Android things introAndroid things intro
Android things intro
Matteo Bonifazi
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Matthew McCullough
 
簡單上手Android studio
簡單上手Android studio簡單上手Android studio
簡單上手Android studio
琨堯 林
 
Android gradle 从入门到gg 0
Android gradle 从入门到gg 0Android gradle 从入门到gg 0
Android gradle 从入门到gg 0
Jun Liu
 
Android - Background operation
Android - Background operationAndroid - Background operation
Android - Background operation
Matteo Bonifazi
 
Android Fundamentals - Day 2
Android Fundamentals - Day 2Android Fundamentals - Day 2
Android Fundamentals - Day 2
Mohammad Tarek
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
Amr Salman
 
Introduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding libraryIntroduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding library
Kaushal Dhruw
 
Gradle for Android Developers
Gradle for Android DevelopersGradle for Android Developers
Gradle for Android Developers
Josiah Renaudin
 
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
Deepu S Nath
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
Kevin He
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & Beyond
Kaushal Dhruw
 
Gradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionGradle & Android Studio - Introduction
Gradle & Android Studio - Introduction
Kevin Pelgrims
 
Android Application Fundamentals
Android Application FundamentalsAndroid Application Fundamentals
Android Application Fundamentals
Vikalp Jain
 
New to android studio
New to android studioNew to android studio
New to android studio
Engine Bai
 
A Deep Dive into Open Source Android Development
A Deep Dive into Open Source Android DevelopmentA Deep Dive into Open Source Android Development
A Deep Dive into Open Source Android Development
David Wu
 
Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3Mastering Maven 2.0 In 1 Hour V1.3
Mastering Maven 2.0 In 1 Hour V1.3
Matthew McCullough
 
Ad

Similar to Gradle,the new build system for android (20)

Build your android app with gradle
Build your android app with gradleBuild your android app with gradle
Build your android app with gradle
Swain Loda
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
Jeevesh Pandey
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android project
Shaka Huang
 
Android Studio 3 - Dependency-Aware Build Variants and Product Flavors
Android Studio 3 - Dependency-Aware Build Variants and Product FlavorsAndroid Studio 3 - Dependency-Aware Build Variants and Product Flavors
Android Studio 3 - Dependency-Aware Build Variants and Product Flavors
Stefan Martynkiw
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
René Winkelmeyer
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
NexThoughts Technologies
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
Roberto Pérez Alcolea
 
Gradle build capabilities
Gradle build capabilities Gradle build capabilities
Gradle build capabilities
Zeinab Mohamed Abdelmawla
 
Gradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesGradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypes
Strannik_2013
 
GraalVM and Oracle's Documentation Trends.pdf
GraalVM and Oracle's Documentation Trends.pdfGraalVM and Oracle's Documentation Trends.pdf
GraalVM and Oracle's Documentation Trends.pdf
ohupalo
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development Pipeline
GlobalLogic Ukraine
 
Next Step, Android Studio!
Next Step, Android Studio!Next Step, Android Studio!
Next Step, Android Studio!
Édipo Souza
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
Gocd – Kubernetes/Nomad Continuous Deployment
Gocd – Kubernetes/Nomad Continuous DeploymentGocd – Kubernetes/Nomad Continuous Deployment
Gocd – Kubernetes/Nomad Continuous Deployment
Leandro Totino Pereira
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
Сергей Моренец: "Gradle. Write once, build everywhere"
Сергей Моренец: "Gradle. Write once, build everywhere"Сергей Моренец: "Gradle. Write once, build everywhere"
Сергей Моренец: "Gradle. Write once, build everywhere"
Provectus
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
Michael Angelo Rivera
 
tools cli java
tools cli javatools cli java
tools cli java
TiNguyn863920
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
Ryan Cuprak
 
Gradle: One technology to build them all
Gradle: One technology to build them allGradle: One technology to build them all
Gradle: One technology to build them all
Bonitasoft
 
Build your android app with gradle
Build your android app with gradleBuild your android app with gradle
Build your android app with gradle
Swain Loda
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android project
Shaka Huang
 
Android Studio 3 - Dependency-Aware Build Variants and Product Flavors
Android Studio 3 - Dependency-Aware Build Variants and Product FlavorsAndroid Studio 3 - Dependency-Aware Build Variants and Product Flavors
Android Studio 3 - Dependency-Aware Build Variants and Product Flavors
Stefan Martynkiw
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
Roberto Pérez Alcolea
 
Gradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesGradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypes
Strannik_2013
 
GraalVM and Oracle's Documentation Trends.pdf
GraalVM and Oracle's Documentation Trends.pdfGraalVM and Oracle's Documentation Trends.pdf
GraalVM and Oracle's Documentation Trends.pdf
ohupalo
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development Pipeline
GlobalLogic Ukraine
 
Next Step, Android Studio!
Next Step, Android Studio!Next Step, Android Studio!
Next Step, Android Studio!
Édipo Souza
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
Gocd – Kubernetes/Nomad Continuous Deployment
Gocd – Kubernetes/Nomad Continuous DeploymentGocd – Kubernetes/Nomad Continuous Deployment
Gocd – Kubernetes/Nomad Continuous Deployment
Leandro Totino Pereira
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
Сергей Моренец: "Gradle. Write once, build everywhere"
Сергей Моренец: "Gradle. Write once, build everywhere"Сергей Моренец: "Gradle. Write once, build everywhere"
Сергей Моренец: "Gradle. Write once, build everywhere"
Provectus
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
Ryan Cuprak
 
Gradle: One technology to build them all
Gradle: One technology to build them allGradle: One technology to build them all
Gradle: One technology to build them all
Bonitasoft
 
Ad

Recently uploaded (20)

How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 

Gradle,the new build system for android

  • 1. The new build system for Android
  • 2. Overview • Gradle basics • Gradle Plugins • Gradle and Studio • Demos • Gradle 与TV版 • Resources
  • 3. What’s Gradle? 1. https://gradle.org 2. https://en.wikipedia.org/wiki/Gradle • Gradle is an open source build automation system. • Grade introduces DSL instead of the more traditional XML form of declaring the project configuration. • focused around Java, Groovy and Scala development and deployment, but more languages and project workflows are on the roadmap. • Gradle can automate the building, testing, publishing, deployment.
  • 4. Why Gradle? 1. Why Gradle? 2. Why choose Gradle? • create custom build logic through plugins. • dependency management • Plugins can expose their own DSL and their own API for build files to use. • Gradle combines the best features from other build tools.
  • 5. Installing Gradle 1. gradle installation • requires a Java JDK or JRE to be installed, version 6 or higher • Gradle ships with its own Groovy library, therefore Groovy does not need to be installed. • Any existing Groovy installation is ignored by Gradle. • Gradle uses whatever JDK it finds in your path • download (http://gradle.org/downloads) • unpacking • add GRADLE_HOME/bin to your PATH environment variable • Android Studio Project includes grade
  • 6. Groovy 1. http://learnxinyminutes.com/docs/groovy/ • http://groovy-lang.org/ • The language used by Gradle • Great similarity to Java • builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
  • 7. Build Script Basics 1. http://rominirani.com/2014/07/28/gradle-tutorial-part-1-installation-setup/ 2. https://gradle.org/docs/current/userguide/tutorial_using_tasks.html#N101A9 • Project What a project represents depends on what it is that you are doing with Gradle • Task A task represents some atomic piece of work which a build performs.This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository. • Plugin A plugin is a mechanism by which we can extend the capabilities of Gradle .
  • 8. Demo 1. http://rominirani.com/2014/07/28/gradle-tutorial-part-1-installation-setup/ //defaultTasks 'buildTask' task compileTask << { System.out.println "compiling..." } task buildTask << { //task buildTask (dependsOn:compileTask) << { System.out.println "building..." } build.gradle
  • 9. 2.Gradle Plugin • Gradle plugin for Java • Gradle plugin for Android • for eclipse,idea,findbugs,c,cpp,oc,jetty…… 1. https://gradle.org/docs/current/userguide/plugins.html 2. https://gradle.org/docs/current/userguide/standard_plugins.html
  • 10. Gradle Plugin for Java • Source sets • Tasks • Project layout • Dependency management • ··· 1. http://gradle.org/docs/current/userguide/java_plugin.html
  • 11. Demo 1. http://rominirani.com/2014/07/28/gradle-tutorial-part-2-java-projects/ apply plugin: ‘java' // packaged with grade archivesBaseName = "quote" version = '1.0-FINAL' repositories { mavenCentral() } dependencies { compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2' testCompile group: 'junit', name: 'junit', version: '4.+' } build.gradle
  • 12. Gradle Plugin for Android 1. http://tools.android.com/tech-docs/new-build-system/user-guide 2. https://www.youtube.com/watch?v=LCJAgPkpmR0 3. http://tools.android.com/build • Published in May, 2013 • 1.0 Released in Dec, 2014 • git clone https://android.googlesource.com/platform/prebuilts/gr adle-plugin
  • 13. Goals of the new build system • Make it easy to reuse code and resources • Make it easy to create several variants of an application, either for multi-apk distribution or for different flavors of an application • Make it easy to configure, extend and customize the build process • Good IDE integration 1. http://tools.android.com/tech-docs/new-build-system/user-guide
  • 14. Android Plugin DSL Reference 1. Android Plugin DSL Reference defaultConfig{} signingConfigs{} productFlavors{} buildTypes{} BuildType ProductFlavor signingConfig LintOptions ……{} Blocks DSL types
  • 15. signing Configs • configuration of how an application is signed • what can be customised? • keyAlias • keyPassword • storeFile • storePassword • storeType • hide key password 1. http://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file- using-gradle
  • 16. Product Flavors • A product flavor defines a customized version of the application build by the project. A single project can have different flavors which change the generated application • This new concept is designed to help when the differences are very, very minimum • Although different flavors could be very different applications, using Library Projects is a better use case for this, and the build system still supports this. 1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
  • 17. What can be customised by Product Flavor? • minSdkVersion • targetSdkVersion • versionCode • versionName • package name (overrides value from manifest) 1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts • release signing info (keystore, key alias, passwords,…) • BuildConfig: Ability to provide custom Java code • NDK ABI filter (Not implemented yet) • Additionally, Product Flavor can provide their own source code, resources and manifest.
  • 18. Build Types • A build type allows configuration of how an application is packaged for debugging or release purpose. • This concept is not meant to be used to create different versions of the same application. This is orthogonal to Product Flavor. 1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
  • 19. What can be customised by Build Types? • manifest debuggable flag • native compilation debug flag • proguard enabled + specific rules • debug signing flag (ie whether to use debug key or release key) • package name suffix (2) • Buildconfig • DEBUG flag. Set automatically based on the manifest debuggable flag. • Ability to provide custom Java code. • Types "Release" and "Debug" are automatically created and can be reconfigured 1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts
  • 20. Build Variants 1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts • Build Type + Product Flavor = Build Variant type1 type2 flavor1 flavor1-type1 flavor1-type2 flavor2 flavor2-type1 flavor2-type2
  • 22. Dependencies • Simply include any artifacts provided by mavenCentral() … dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.2' compile 'com.jpardogo.flabbylistview:library:+' compile 'com.jpardogo.googleprogressbar:library:+' compile 'com.mcxiaoke.volley:library:1.0.+' compile 'com.umeng.analytics:analytics:5.2.4' } … build.gradle
  • 23. Dependencies • 指定你自己的仓库地址 … repositories { maven { url "http://repo.mycompany.com/repo" } } … build.gradle • 常见的maven仓库 • http://search.maven.org (mavenCentral()) • https://bintray.com/bintray/jcenter (jcenter()) • http://maven.oschina.net/home.html • ( maven{ url 'http://maven.oschina.net/content/groups/public/'} )
  • 24. Multi Project Build (Library Projects) 1. http://tools.android.com/tech-docs/new-build-system/build-system-concepts • use the settings.gradle files to declare library projects • add library projects as "compile" dependency • 自定义library project位置 … include ':letvCore' include ':loginLib' include ':letv' project(':letvCore').projectDir = new File(rootDir, "../librarys/letvCore") project(':loginLib').projectDir = new File(rootDir, "../librarys/loginLib") … settings.gradle
  • 25. Demo • 如何通过一套代码开发不同功能的apk • git clone https://github.com/ghuiii/gradledemo.git
  • 26. 代码合并规则 • 图片、音频、 XML 类型的 Drawable 等资源文件,将会进行文件级的覆盖 • 字符串、颜色值、整型等资源以及 AndroidManifest.xml ,将会进行元素级 的覆盖 • 代码资源,同一个类, buildTypes 、 productFlavors 、 main 中只能存在 一次,否则会有类重复的错误 • 覆盖等级为:buildTypes > productFlavors > main 1. http://ask.android-studio.org/?/article/30
  • 27. Gradle plugin for android 常见task 1. http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Tasks
  • 28. Studio&Gradle 1. http://developer.android.com/tools/building/index.html • Good IDE integration • The IDE doesn’t do a build anymore • Building and Running from Android Studio • Building and Running from Command Line
  • 31. Resources • http://gradle.org/docs/current/userguide/userguide.html • http://rominirani.com/2014/07/28/gradle-tutorial-series-an- overview/ • http://avatarqing.github.io/Gradle-Plugin-User-Guide-Chinese- Verision/introduction/README.html • http://developer.android.com/sdk/installing/studio-build.html • http://apdr.qiniudn.com/index.html