Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Level Up with Android Build Variants
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Phil Shadlyn
July 07, 2015
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Level Up with Android Build Variants
Phil Shadlyn
July 07, 2015
Transcript
19 slides
Level Up with Android Build Variants
Why do I care? • It’d be nice to build
multiple variants of an Android app from a single code base • Common variants include: ◦ debug/release ◦ free/paid ◦ dev/staging/production
With Eclipse and Ant • Code base contained in library
project • Needed an additional project for each variant which referenced library project
None
With Android Studio and Gradle • All contained in single
project • Define Build Types and Product Flavours in build.gradle file • Create src directories to hold code specific to each build type/flavour
None
Build Types • Define how to build and package your
app • debug and release build types created by default • Can create your own
signingConfigs { release { storeFile file( 'release.keystore' ) storePassword 'verysecurepassw0rd'
keyAlias 'release' keyPassword 'verysecurepassw0rd' } } buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile( 'proguard-android.txt' ), 'proguard-rules.pro' signingConfig signingConfigs.release } debug{ applicationIdSuffix ".debug" signingConfig null } }
Product Flavours • Provide alternative code, resources or configuration •
Examples: ◦ Different API endpoints for dev/staging/production environment ◦ Free/paid version
Free / Paid • Provide alternative resources and code by
creating flavour directory • Gradle creates combination of each Build Type and Product Flavour
productFlavors{ free{ applicationId "com.physphil.android.sandbox.free" } paid{ applicationId "com.physphil.android.sandbox.pro" } }
} dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' compile 'de.greenrobot:eventbus:2.4.0' // Only full version requires network calls paidCompile 'com.squareup.retrofit:retrofit:1.9.0' paidCompile 'com.squareup.okhttp:okhttp:2.2.0' }
None
Free / Paid
Dev / Staging / Production • Define flavour for each
server environment • Store API base URL in a Config class • Create directory in src for each flavour, which contains an instance of Config
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile(
'proguard-android.txt' ), 'proguard-rules.pro' signingConfig signingConfigs.release } debug { applicationIdSuffix ".debug" signingConfig null } } productFlavors { dev staging production }
None
That’s Not All! • Modify more build parameters • Include
libraries, code, Activities etc only when required • Lots of examples in official docs
Additional Resources • http://tools.android.com/tech-docs/new-build- system/user-guide • https://developer.android. com/tools/building/configuring-gradle.html • http://www.vogella.
com/tutorials/AndroidBuild/article.html
Questions?
More Decks by Phil Shadlyn
See All by Phil Shadlyn
Kotlin Sequences: Deep Dive
physphil
1
230
Dealing with Imposter Syndrome
physphil
4
110
What is Kotlin Serialization? (And should I use it?)
physphil
0
240
I Wrote an App with Architecture Components
physphil
6
1.2k
Android Auto - Drive Your Car, Use Your Phone, and Don't Hurt Anyone
physphil
0
330
Grokking Android Studio
physphil
0
210
Download This! Tips for Successfully Promoting Your Android App
physphil
0
120
Android Networking (Without Going Crazy)
physphil
0
120
Other Decks in Programming
See All in Programming
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
360
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
760
AI Augmentation Techniques with Liberty
ivargrimstad
1
490
AI-Powered Domain-Driven Design
ziobrando
0
450
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
260
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
320
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
190
LLM 101
dalinaum
0
500
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.3k
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
120
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
250
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
380
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
560
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
300
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
990
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
340
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Balancing Empowerment & Direction
lara
6
1.4k